Passed
Push — master ( 657ba7...501391 )
by Andrii
02:17
created

collector.test.ts ➔ collectorCall   A

Complexity

Conditions 1

Size

Total Lines 12
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 12
dl 0
loc 12
rs 9.8
c 0
b 0
f 0
1
import schema = require("./schema.json")
2
import { extractDefaults, regexpize } from "./utils";
3
import type {CollectingArg} from "./ts-swiss.types"
4
import collector = require("./collector");
5
6
const defaults = extractDefaults(schema)
7
8
function collectorCall(selectors: CollectingArg["selectors"], parent?: CollectingArg["parent"]) {
9
  return Object.keys(collector({
10
    identifiers: {},
11
    identifierParser: regexpize(defaults.identifierPattern, "g"),
12
    identifierMatchIndex: defaults.identifierMatchIndex,
13
    identifierCleanupParser: regexpize(defaults.identifierCleanupSearch, "g"),
14
    identifierCleanupReplace: defaults.identifierCleanupReplace,
15
    allowedAtRules: new Set(defaults.allowedAtRules)  
16
  })({
17
    selectors: selectors.reverse(),
18
    ...parent && {parent}
19
  }))
20
}
21
22
it("demo", () => expect(collectorCall([
23
  ".class [id='.positive_mistake'] .ke-bab"
24
])).toStrictEqual([
25
  "class", "positive_mistake", "ke-bab"
26
]))
27
28
describe("tailwind", () => {
29
  it("TBD", () => expect(collectorCall([
30
    ".group-hover\\:bg-pink-200",
31
    ".w-0\\.5",
32
    ".w-1\\/2",
33
    '.\\32xl',
34
    '.\\32xl\\:container',
35
  ])).not.toStrictEqual([
36
    "group-hover:bg-pink-200",
37
    "w-0.5",
38
    "w-1/2",
39
    "2xl",
40
    "2xl:container",
41
  ]))
42
43
  it("cur", () => expect(collectorCall([
44
    ".group-hover\\:bg-pink-200",
45
    ".w-0\\.5",
46
    ".w-1\\/2",
47
    '.\\32xl',
48
    '.\\32xl\\:container',
49
  ])).toStrictEqual([
50
    "group-hover:bg-pink-200",
51
    "w-0.5",
52
    "w-1/2",
53
  ]))
54
})
55
56
describe("at-rule", () => {
57
  /** Appears in material
58
   * ```css
59
   * @-webkit-keyframes mdc-checkbox-unchecked-indeterminate-mixedmark {
60
   *   0%, 68.2% {}
61
   * } */  
62
  it("without keyframes", () => expect(collectorCall(
63
    ['0%', '68.2%'],
64
    {"type": "atrule", "name": "keyframes"}
65
  )).toStrictEqual([
66
  ]))
67
  
68
  it("with media", () => expect(collectorCall(
69
    ['.inside-media'],
70
    {"type": "atrule", "name": "media"}
71
  )).toStrictEqual([
72
    "inside-media"
73
  ]))
74
})