UNPKG

1.62 kBJavaScriptView Raw
1
2import { parse } from './style-parse';
3
4it('should parse style strings', () => {
5 expect(parse('-')).toEqual({
6 });
7 expect(parse('-CP10G_blue_D_red,Cyan_')).toEqual({
8 'colorize': true,
9 'padding': 10,
10 'background': 'blue',
11 'detail': ['red', 'Cyan']
12 });
13 expect(parse('-Zx')).toEqual({
14 'zoom': 'x'
15 });
16 expect(parse('-G_eee_D_fff_-D01_aaa,bababa_')).toEqual({
17 'background': '#eee',
18 'detail': ['#fff'],
19 'detailsym': [
20 {
21 'index': 1,
22 'detail': ['#aaa', '#bababa']
23 }
24 ]
25 });
26 expect(parse('--D01_yellow_')).toEqual({
27 'detailsym': [
28 {
29 'index': 1,
30 'detail': ['yellow']
31 }
32 ]
33 });
34 expect(parse('---myclass!')).toEqual({
35 'classes': 'myclass'
36 });
37 expect(parse('---!myid!')).toEqual({
38 'id': 'myid'
39 });
40 expect(parse('-CP10G_blue_D_red,Cyan_Z1.1-D01_blue_D02_yellow,green_-primary blinking!cursor!')).toEqual({
41 'colorize': true,
42 'padding': 10,
43 'background': 'blue',
44 'detail': ['red', 'Cyan'],
45 'zoom': 1.1,
46 'detailsym': [
47 {
48 'index': 1,
49 'detail': ['blue']
50 },
51 {
52 'index': 2,
53 'detail': ['yellow', 'green']
54 }
55 ],
56 'classes': 'primary blinking',
57 'id': 'cursor'
58 });
59})
60
61it('should parse without breaking on bad data', () => {
62 expect(parse()).toEqual({
63 });
64 expect(parse(undefined)).toEqual({
65 });
66 expect(parse("S10000500x500-CZ5")).toEqual({
67 });
68 expect(parse(['-Zx'])).toEqual({
69 });
70 expect(parse({ "this": "that" })).toEqual({
71 });
72})