Skip to content

Commit fd969dc

Browse files
committed
More tests. In a helpful turn of events Jest, has decided to stop working.
1 parent c6b28e4 commit fd969dc

File tree

5 files changed

+118
-76
lines changed

5 files changed

+118
-76
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ root = true
33
[*]
44
end_of_line = lf
55
insert_final_newline = true
6-
indent_style = space
6+
indent_style = tabs
77
indent_size = 2
88
charset = utf-8
99
trim_trailing_whitespace = true

.eslintrc.json

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,49 @@
11
{
2-
"root": true,
3-
"rules": {
4-
"indent": [2, 2, { "SwitchCase": 1 }],
5-
"semi": [2, "always"],
6-
"keyword-spacing": [2, { "before": true, "after": true }],
7-
"space-before-blocks": [2, "always"],
8-
"no-mixed-spaces-and-tabs": [2, "smart-tabs"],
9-
"no-cond-assign": 0,
10-
"no-unused-vars": 2,
11-
"object-shorthand": [2, "always"],
12-
"no-const-assign": 2,
13-
"no-class-assign": 2,
14-
"no-this-before-super": 2,
15-
"no-var": 2,
16-
"no-unreachable": 2,
17-
"valid-typeof": 2,
18-
"quote-props": [2, "as-needed"],
19-
"one-var": [2, "never"],
20-
"prefer-arrow-callback": 2,
21-
"prefer-const": [2, { "destructuring": "all" }],
22-
"arrow-spacing": 2,
23-
"no-inner-declarations": 0
24-
},
2+
"root": true,
3+
"rules": {
4+
"indent": ["error", "tab"],
5+
"semi": [2, "always"],
6+
"keyword-spacing": [2, { "before": true, "after": true }],
7+
"space-before-blocks": [2, "always"],
8+
"no-mixed-spaces-and-tabs": [2, "smart-tabs"],
9+
"no-cond-assign": 0,
10+
"no-unused-vars": 2,
11+
"object-shorthand": [2, "always"],
12+
"no-const-assign": 2,
13+
"no-class-assign": 2,
14+
"no-this-before-super": 2,
15+
"no-var": 2,
16+
"no-unreachable": 2,
17+
"valid-typeof": 2,
18+
"quote-props": [2, "as-needed"],
19+
"one-var": [2, "never"],
20+
"prefer-arrow-callback": 2,
21+
"prefer-const": [2, { "destructuring": "all" }],
22+
"arrow-spacing": 2,
23+
"no-inner-declarations": 0
24+
},
2525

26-
"env": {
27-
"es6": true,
28-
"browser": true,
29-
"node": true,
30-
"jest": true
31-
},
32-
"extends": [
33-
"eslint:recommended",
34-
"plugin:import/errors",
35-
"plugin:import/warnings"
36-
],
37-
"plugins": ["import"],
38-
"parserOptions": {
39-
"ecmaVersion": 6,
40-
"sourceType": "module"
41-
},
42-
"settings": {
43-
"import/resolver": {
44-
"node": {
45-
"extensions": [".js"]
46-
}
47-
}
48-
}
26+
"env": {
27+
"es6": true,
28+
"browser": true,
29+
"node": true,
30+
"jest": true
31+
},
32+
"extends": [
33+
"eslint:recommended",
34+
"plugin:import/errors",
35+
"plugin:import/warnings"
36+
],
37+
"plugins": ["import"],
38+
"parserOptions": {
39+
"ecmaVersion": 6,
40+
"sourceType": "module"
41+
},
42+
"settings": {
43+
"import/resolver": {
44+
"node": {
45+
"extensions": [".js"]
46+
}
47+
}
48+
}
4949
}

.prettierrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
useTabs: false
1+
useTabs: true
22
singleQuote: true
33
trailingComma: 'es5'

src/parsers/svelte_tags.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
const RE_SVELTE_SELFCLOSING =
2-
'\\s*<svelte:([a-z]+) (?:(?:[a-z:]+(?:="*[a-z]+"*)*)\\s*)*\\/>';
2+
'\\s*<svelte:([a-z]+) (?:(?:[a-z:]+(?:="*[a-z]+"*)*)\\s*)*\\/>';
33
const RE_SVELTE_START =
4-
'\\s*<svelte:([a-z]+)\\s*(?:(?:[a-z:]+(?:="*[a-z]+"*)*)\\s*)*>';
4+
'\\s*<svelte:([a-z]+)\\s*(?:(?:[a-z:]+(?:="*[a-z]+"*)*)\\s*)*>';
55
const RE_SVELTE_END = '\\s*<\\/\\s*svelte:([a-z]+)\\s*>';
66

77
const RE_SVELTE_TAG = new RegExp(
8-
RE_SVELTE_SELFCLOSING + '|' + RE_SVELTE_START + '|' + RE_SVELTE_END
8+
RE_SVELTE_SELFCLOSING + '|' + RE_SVELTE_START + '|' + RE_SVELTE_END
99
);
1010

1111
export function parse_svelte_tag(eat, value, silent) {
12-
const match = RE_SVELTE_TAG.exec(value);
12+
const match = RE_SVELTE_TAG.exec(value);
1313

14-
if (match) {
15-
if (silent) return true;
14+
if (match) {
15+
if (silent) return true;
1616

17-
return eat(match[0])({
18-
type: 'svelteTag',
19-
value: match[0],
20-
name: match[1],
21-
});
22-
}
17+
return eat(match[0])({
18+
type: 'svelteTag',
19+
value: match[0],
20+
name: match[1],
21+
});
22+
}
2323
}

test/parsers.spec.js

Lines changed: 58 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,65 @@ import { parse_svelte_tag } from '../src/parsers';
22

33
// I have no idea what the unified/ remark eat function returns but i need to fake it.
44
const eat = value => node => ({
5-
value,
6-
node,
5+
value,
6+
node,
77
});
88

99
describe('parse_svelte_tag', () => {
10-
test('it should correctly match and parse any svelte tag: component', () => {
11-
const input = '<svelte:component />';
12-
13-
const output = parse_svelte_tag(eat, input, false);
14-
15-
expect(output).toEqual({
16-
value: '<svelte:component />',
17-
node: {
18-
value: '<svelte:component />',
19-
name: 'component',
20-
type: 'svelteTag',
21-
},
22-
});
23-
});
10+
const svelte_tags = [
11+
['component', 'svelte:component'],
12+
['self', 'svelte:self'],
13+
['window', 'svelte:window'],
14+
['body', 'svelte:body'],
15+
['options', 'svelte:options'],
16+
];
17+
18+
svelte_tags.forEach(([name, component]) => {
19+
test(`it should it should correctly match and parse any svelte tag: ${name}`, () => {
20+
expect(parse_svelte_tag(eat, `<${component} />`, false)).toEqual({
21+
value: `<${component} />`,
22+
node: {
23+
value: `<${component} />`,
24+
name,
25+
type: 'svelteTag',
26+
},
27+
});
28+
});
29+
30+
test(`it should it should correctly match and parse any svelte tag ignoring whitespace: ${name}`, () => {
31+
expect(parse_svelte_tag(eat, ` <${component} />`, false)).toEqual({
32+
value: ` <${component} />`,
33+
node: {
34+
value: ` <${component} />`,
35+
name,
36+
type: 'svelteTag',
37+
},
38+
});
39+
});
40+
41+
test(`it should it should correctly match and parse any svelte tag regardless of attributes: ${name}`, () => {
42+
const output = parse_svelte_tag(
43+
eat,
44+
`<${component} foo=bar quu="quux" hello on:click on:keypress={boo} />`,
45+
false
46+
);
47+
48+
expect(output).toEqual({
49+
value: `<${component} foo=bar quu="quux" hello on:click on:keypress={boo} />`,
50+
node: {
51+
value: `<${component} foo=bar quu="quux" hello on:click on:keypress={boo} />`,
52+
name,
53+
type: 'svelteTag',
54+
},
55+
});
56+
});
57+
});
58+
59+
test('in silent mode, matches should return true', () => {
60+
const input = '<svelte:component />';
61+
62+
const output = parse_svelte_tag(eat, input, true);
63+
64+
expect(output).toBe(true);
65+
});
2466
});

0 commit comments

Comments
 (0)