-
Notifications
You must be signed in to change notification settings - Fork 0
/
direction_attribute.test.js
64 lines (58 loc) · 3.14 KB
/
direction_attribute.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
* Copyright 2023 DenkiYagi Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import * as direction_attribute from './direction_attribute.mjs';
import { DOMParser, XMLSerializer } from '@xmldom/xmldom'
test.each([
{input: "", expected: []},
{input: "30", expected: ["30"]},
{input: "30 30 _ _", expected: ["30", "30", "_", "_"]},
{input: "dashed dashed dotted dashed", expected: ["dashed", "dashed", "dotted", "dashed"]},
{input: "Cmyk(1, 0, 0, 0)", expected: ["Cmyk(1, 0, 0, 0)"]},
{input: "cmyk(1, 0, 0, 0) cmyk(0, 1, 0, 0) cmyk(0, 0, 1, 0) cmyk(0, 0, 0, 1)", expected: ["cmyk(1, 0, 0, 0)", "cmyk(0, 1, 0, 0)", "cmyk(0, 0, 1, 0)", "cmyk(0, 0, 0, 1)"]},
//{input: "${hide}", expected: ["${hide}"]},
])('属性値を分解できる: "$input"', ({input, expected}) => {
expect(direction_attribute.splitAttributeValue(input)).toStrictEqual(expected);
});
test.each([
{value: "_", expected: '<Grid/>'},
{value: "1", expected: '<Grid test="1"/>'},
{value: "_ _", expected: '<Grid/>'},
{value: "1 _", expected: '<Grid testTop="1" testBottom="1"/>'},
{value: "_ 2", expected: '<Grid testRight="2" testLeft="2"/>'},
{value: "1 2", expected: '<Grid test="1 2"/>'},
{value: "_ _ _", expected: '<Grid/>'},
{value: "1 _ _", expected: '<Grid testTop="1"/>'},
{value: "_ 2 _", expected: '<Grid testRight="2" testLeft="2"/>'},
{value: "_ _ 3", expected: '<Grid testBottom="3"/>'},
{value: "1 _ 3", expected: '<Grid testTop="1" testBottom="3"/>'},
{value: "1 2 3", expected: '<Grid test="1 2 3"/>'},
{value: "_ _ _ _", expected: '<Grid/>'},
{value: "1 _ _ _", expected: '<Grid testTop="1"/>'},
{value: "_ 2 _ _", expected: '<Grid testRight="2"/>'},
{value: "_ _ 3 _", expected: '<Grid testBottom="3"/>'},
{value: "_ _ _ 4", expected: '<Grid testLeft="4"/>'},
{value: "1 _ _ 4", expected: '<Grid testTop="1" testLeft="4"/>'},
{value: "_ 2 3 _", expected: '<Grid testRight="2" testBottom="3"/>'},
{value: "1 2 3 4", expected: '<Grid test="1 2 3 4"/>'},
{value: "_ cmyk(1, 0, 0, 0) cmyk(0, 1, 0, 0) _", expected: '<Grid testRight="cmyk(1, 0, 0, 0)" testBottom="cmyk(0, 1, 0, 0)"/>'},
{value: "dashed _ dotted", expected: '<Grid testTop="dashed" testBottom="dotted"/>'}
])('属性値を方向別の属性に分割できる: "$value"', ({value, expected}) => {
const xml = `<Grid test="${value}"/>`;
const doc = new DOMParser().parseFromString(xml);
direction_attribute.convertAttribute(doc, "//Grid", "test", "testTop", "testRight", "testBottom", "testLeft");
const actual = new XMLSerializer().serializeToString(doc);
expect(actual).toStrictEqual(expected);
});