]> gitweb.factorcode.org Git - factor.git/blob - extra/lint/vocabs/vocabs-tests.factor
scryfall: better moxfield words
[factor.git] / extra / lint / vocabs / vocabs-tests.factor
1 ! Copyright (C) 2022 CapitalEx
2 ! See https://factorcode.org/license.txt for BSD license.
3 USING: accessors arrays assocs compiler.units continuations
4 formatting hash-sets hashtables io io.encodings.utf8 io.files
5 kernel namespaces regexp sequences sequences.deep
6 sequences.parser sets sorting splitting tools.test unicode
7 vocabs vocabs.loader ;
8 IN: lint.vocabs
9
10 <PRIVATE
11 CONSTANT: mock-file "
12 USING: arrays io kernel math math.parser sets
13 hashtables sequences vocabs ;
14 IN: lint.vocabs.testing
15
16 : test-one ( x y -- )
17     + print ;
18
19 : test-two ( x -- x )
20     dup 2array ;
21
22 : test-three ( -- x )
23     HS{ } clone ;
24
25 : test-four ( x -- x )
26     >bin ;
27
28 USE: math.complex
29 : test-five ( x -- ? )
30     malformed-complex? ;
31
32 USE: math.primes
33 "
34 CONSTANT: ignore-postpone-using     "POSTPONE: USING: : nop ( -- ) ;"
35 CONSTANT: ingore-\-using            "\\ USING: : nop ( -- ) ;"
36 CONSTANT: ignore-postpone-use       "POSTPONE: USE: ignore : nop ( -- ) ;"
37 CONSTANT: ignore-\-use              "\\ USE: ignore : nop ( -- ) ;"
38 CONSTANT: ignore-in-string-one      "\"USE:\" \"USING:\" : nop ( -- ) ;"
39 CONSTANT: ignore-in-string-two      "\"asdfasdf USE:\" \"asdfasdf USING:\" : nop ( -- ) ;"
40 CONSTANT: ignore-in-string-three    "\"asdfasdf USE: asdfasdf\" : nop ( -- ) ;"
41 CONSTANT: ignore-in-string-four     "\"asdfasdf USE: asdfasdf\" \"asdfasff USING: asdfasdf\" : nop ( -- ) ;"
42 CONSTANT: ignore-string-with-quote  "\"\\\"USE:\" : nop ( -- ) ;"
43 CONSTANT: ignore-use-regex          "R/ USE: ignore/ : nop ( -- ) ;"
44 CONSTANT: ignore-using-regex        "R/ USING: ignore ;/ : nop ( -- ) ;"
45 CONSTANT: ignore-char-backslash     "CHAR: \\ USING: math.functions ;"
46 CONSTANT: empty-using-statement     "USING: ; nop ( -- ) ;"
47 : ---- ( -- ) "-------------------------------------------------------------------------" print ;
48 PRIVATE>
49
50 "next-token should get the next non-blank string in the stream:" print
51 { "hello" } [ "hello world!"              <sequence-parser> next-token ] unit-test
52 { "hello" } [ "\n    hello \n world!    " <sequence-parser> next-token ] unit-test
53
54 ----
55
56 "next-token should ignore comments:" print
57 { "world!" } [ "! hello\nworld!"                 <sequence-parser> next-token ] unit-test
58 { "world!" } [ "! h\n! e\n! l\n! l\n! o\nworld!" <sequence-parser> next-token ] unit-test
59
60 ----
61
62 "It should work on multiple lines, with multiple imports across the file: " print
63
64 { { "hashtables" "math.primes" "sequences" "sets" "vocabs" } } [ mock-file find-unused-in-string ] unit-test
65
66 ----
67
68 "It should ignore USE: and USING: that have been postponed: " print
69 { { } } [ ignore-postpone-using find-unused-in-string ] unit-test
70 { { } } [ ingore-\-using        find-unused-in-string ] unit-test
71 { { } } [ ignore-postpone-use   find-unused-in-string ] unit-test
72 { { } } [ ignore-\-use          find-unused-in-string ] unit-test
73
74 ----
75
76 "It should ignore USE: and USING: that are in strings: " print
77 { { } } [ ignore-in-string-one     find-unused-in-string ] unit-test
78 { { } } [ ignore-in-string-two     find-unused-in-string ] unit-test
79 { { } } [ ignore-in-string-three   find-unused-in-string ] unit-test
80 { { } } [ ignore-in-string-four    find-unused-in-string ] unit-test
81 { { } } [ ignore-string-with-quote find-unused-in-string ] unit-test
82
83 ----
84
85 "It should ignore CHAR: \\: " print
86 { { "math.functions" } } [ ignore-char-backslash find-unused-in-string ] unit-test
87
88 ----
89
90 "It should ignore USE: and USING: that are in RegEx: " print
91 { { } } [ ignore-use-regex   find-unused-in-string ] unit-test
92 { { } } [ ignore-using-regex find-unused-in-string ] unit-test
93
94 ----
95
96 "It should return empty when no imports have been found: " print
97 { { } } [ empty-using-statement find-unused-in-string ] unit-test
98
99 ----
100
101 "It should forget vocabs that aren't already loaded: " print
102 dictionary get clone 1array [ 
103     "USE: bitcoin.client" find-unused-in-string drop
104     dictionary get clone 
105 ] unit-test
106
107 ----