]> gitweb.factorcode.org Git - factor.git/blob - extra/lint/vocabs/vocabs-tests.factor
Add lint.vocabs to extra
[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-use-regex       "R/ USE: ignore/ : nop ( -- ) ;"
42 CONSTANT: ignore-using-regex     "R/ USING: ignore ;/ : nop ( -- ) ;"
43 CONSTANT: empty-using-statement  "USING: ; nop ( -- ) ;"
44 : ---- ( -- ) "-------------------------------------------------------------------------" print ;
45 PRIVATE>
46
47 "It should work on multiple lines, with multiple imports across the file: " print
48
49 { { "hashtables" "math.primes" "sequences" "sets" "vocabs" } } [ mock-file find-unused-in-string ] unit-test
50
51 ----
52
53 "It should ignore USE: and USING: that have been postponed: " print
54 { { } } [ ignore-postpone-using find-unused-in-string ] unit-test
55 { { } } [ ingore-\-using        find-unused-in-string ] unit-test
56 { { } } [ ignore-postpone-use   find-unused-in-string ] unit-test
57 { { } } [ ignore-\-use          find-unused-in-string ] unit-test
58
59 ----
60
61 "It should ignore USE: and USING: that are in strings: " print
62 { { } } [ ignore-in-string-one find-unused-in-string ] unit-test
63 { { } } [ ignore-in-string-two find-unused-in-string ] unit-test
64 { { } } [ ignore-in-string-three find-unused-in-string ] unit-test
65 { { } } [ ignore-in-string-four find-unused-in-string ] unit-test
66
67 ----
68
69 "It should ignore USE: and USING: that are in RegEx: " print
70 { { } } [ ignore-use-regex find-unused-in-string ] unit-test
71 { { } } [ ignore-using-regex find-unused-in-string ] unit-test
72
73 ----
74
75 "IT should return empty when no imports have been found: " print
76 { { } } [ empty-using-statement find-unused-in-string ] unit-test
77
78 ----
79
80 "It should forget vocabs that aren't already loaded: " print
81 dictionary get clone 1array [ 
82     "USE: bitcoin.client" find-unused-in-string drop
83     dictionary get clone 
84 ] unit-test
85
86 ----