]> gitweb.factorcode.org Git - factor.git/blob - extra/lint/vocabs/vocabs-tests.factor
61e5ffa29fb8d44e5c56a00c6f138312d0eef5d9
[factor.git] / extra / lint / vocabs / vocabs-tests.factor
1 ! Copyright (C) 2022 CapitalEx
2 ! See http://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 sets sorting
6 splitting tools.test unicode vocabs vocabs.loader ;
7 IN: lint.vocabs
8
9 <PRIVATE
10 CONSTANT: mock-file "
11 USING: arrays io kernel math math.parser sets
12 hashtables sequences vocabs ;
13 IN: lint.vocabs.testing
14
15 : test-one ( x y -- )
16     + print ;
17
18 : test-two ( x -- x )
19     dup 2array ;
20
21 : test-three ( -- x )
22     HS{ } clone ;
23
24 : test-four ( x -- x )
25     >bin ;
26
27 USE: math.complex
28 : test-five ( x -- ? )
29     malformed-complex? ;
30
31 USE: math.primes
32 "
33 CONSTANT: ignore-postpone-using     "POSTPONE: USING: : nop ( -- ) ;"
34 CONSTANT: ingore-\-using            "\\ USING: : nop ( -- ) ;"
35 CONSTANT: ignore-postpone-use       "POSTPONE: USE: ignore : nop ( -- ) ;"
36 CONSTANT: ignore-\-use              "\\ USE: ignore : nop ( -- ) ;"
37 CONSTANT: ignore-in-string-one      "\"USE:\" \"USING:\" : nop ( -- ) ;"
38 CONSTANT: ignore-in-string-two      "\"asdfasdf USE:\" \"asdfasdf USING:\" : nop ( -- ) ;"
39 CONSTANT: ignore-in-string-three    "\"asdfasdf USE: asdfasdf\" : nop ( -- ) ;"
40 CONSTANT: ignore-in-string-four     "\"asdfasdf USE: asdfasdf\" \"asdfasff USING: asdfasdf\" : nop ( -- ) ;"
41 CONSTANT: ignore-string-with-quote  "\"\\\"USE:\" : nop ( -- ) ;"
42 CONSTANT: ignore-use-regex          "R/ USE: ignore/ : nop ( -- ) ;"
43 CONSTANT: ignore-using-regex        "R/ USING: ignore ;/ : nop ( -- ) ;"
44 CONSTANT: empty-using-statement     "USING: ; nop ( -- ) ;"
45 : ---- ( -- ) "-------------------------------------------------------------------------" print ;
46 PRIVATE>
47
48 "It should work on multiple lines, with multiple imports across the file: " print
49
50 { { "hashtables" "math.primes" "sequences" "sets" "vocabs" } } [ mock-file find-unused-in-string ] unit-test
51
52 ----
53
54 "It should ignore USE: and USING: that have been postponed: " print
55 { { } } [ ignore-postpone-using find-unused-in-string ] unit-test
56 { { } } [ ingore-\-using        find-unused-in-string ] unit-test
57 { { } } [ ignore-postpone-use   find-unused-in-string ] unit-test
58 { { } } [ ignore-\-use          find-unused-in-string ] unit-test
59
60 ----
61
62 "It should ignore USE: and USING: that are in strings: " print
63 { { } } [ ignore-in-string-one     find-unused-in-string ] unit-test
64 { { } } [ ignore-in-string-two     find-unused-in-string ] unit-test
65 { { } } [ ignore-in-string-three   find-unused-in-string ] unit-test
66 { { } } [ ignore-in-string-four    find-unused-in-string ] unit-test
67 { { } } [ ignore-string-with-quote find-unused-in-string ] unit-test
68
69 ----
70
71 "It should ignore USE: and USING: that are in RegEx: " print
72 { { } } [ ignore-use-regex   find-unused-in-string ] unit-test
73 { { } } [ ignore-using-regex find-unused-in-string ] unit-test
74
75 ----
76
77 "It should return empty when no imports have been found: " print
78 { { } } [ empty-using-statement find-unused-in-string ] unit-test
79
80 ----
81
82 "It should forget vocabs that aren't already loaded: " print
83 dictionary get clone 1array [ 
84     "USE: bitcoin.client" find-unused-in-string drop
85     dictionary get clone 
86 ] unit-test
87
88 ----