]> gitweb.factorcode.org Git - factor.git/blob - extra/gap-buffer/gap-buffer-tests.factor
Fixes #2966
[factor.git] / extra / gap-buffer / gap-buffer-tests.factor
1 USING: kernel sequences tools.test gap-buffer strings math ;
2
3 ! test copy-elements
4 { { 0 3 4 3 4 5 } }
5 [ { 0 1 2 3 4 5 } dup [ -2 3 5 ] dip copy-elements ] unit-test
6
7 { { 0 1 2 1 2 5 } }
8 [ { 0 1 2 3 4 5 } dup [ 2 2 0 ] dip copy-elements ] unit-test
9
10 { "01234567856" }
11 [ "01234567890" dup [ 4 6 4 ] dip copy-elements ] unit-test
12
13 ! test sequence protocol (like, length, nth, set-nth)
14 { "gap buffers are cool" }
15 [ "gap buffers are cool" <gb> "" like ] unit-test
16
17 ! test move-gap-back-inside
18 { t f }
19 [ 5 "0123456" <gb> move-gap-forward? [ move-gap-back-inside? 2nip ] dip ] unit-test
20
21 { "0123456" }
22 [ "0123456" <gb> 5 over move-gap >string ] unit-test
23
24 ! test move-gap-forward-inside
25 { t }
26 [ "I once ate a spaniel" <gb> 15 over move-gap 17 swap move-gap-forward-inside? 2nip ] unit-test
27
28 { "I once ate a spaniel" }
29 [ "I once ate a spaniel" <gb> 15 over move-gap 17 over move-gap >string ] unit-test
30
31 ! test move-gap-back-around
32 { f f }
33 [ 2 "terriers are ok too" <gb> move-gap-forward? [ move-gap-back-inside? 2nip ] dip ] unit-test
34
35 { "terriers are ok too" }
36 [ "terriers are ok too" <gb> 2 over move-gap >string ] unit-test
37
38 ! test move-gap-forward-around
39 { f t }
40 [
41     "god is nam's best friend" <gb>
42     2 over move-gap 22 over position>index swap move-gap-forward?
43     [ move-gap-forward-inside? 2nip ] dip
44 ] unit-test
45
46 { "god is nam's best friend" }
47 [ "god is nam's best friend" <gb> 2 over move-gap 22 over move-gap >string ] unit-test
48
49 ! test changing buffer contents
50 { "factory" }
51 [ "factor" <gb> CHAR: y 6 pick insert* >string ] unit-test
52
53 ! test inserting multiple elements in different places. buffer should grow
54 { "refractory" }
55 [ "factor" <gb> CHAR: y 6 pick insert* "re" 0 pick insert* CHAR: r 3 pick insert* >string ] unit-test
56
57 ! test deleting elements. buffer should shrink
58 { "for" }
59 [ "factor" <gb> 3 [ 1 over delete* ] times >string ] unit-test
60
61 ! more testing of nth and set-nth
62 { "raptor" }
63 [ "factor" <gb> CHAR: p 2 pick set-nth 5 over nth 0 pick set-nth >string ] unit-test
64
65 ! test stack/queue operations
66 { "slaughter" }
67 [ "laughter" <gb> CHAR: s over push-start >string ] unit-test
68
69 { "pantonio" }
70 [ "pant" <gb> "onio" over push-end >string ] unit-test
71
72 { CHAR: f "actor" }
73 [ "factor" <gb> dup pop-start swap >string ] unit-test
74
75 { CHAR: s "pant" }
76 [ "pants" <gb> dup pop-end swap >string ] unit-test
77
78 { "end this is the " }
79 [ "this is the end " <gb> 4 over rotate >string ] unit-test
80
81 { "your jedi training is finished " }
82 [ "finished your jedi training is " <gb> -9 over rotate >string ] unit-test