Passed
Push — master ( 299505...478460 )
by Andrii
02:46
created

src/collector.test.ts   A

Complexity

Total Complexity 1
Complexity/F 1

Size

Lines of Code 73
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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