Clean up each-line combinator a bit, add unit tests

db4
Slava Pestov 2008-12-02 20:46:09 -06:00
parent 3385cf5992
commit cb56943f81
2 changed files with 33 additions and 4 deletions

View File

@ -1,8 +1,37 @@
IN: documents.tests IN: documents.tests
USING: documents namespaces tools.test ; USING: documents namespaces tools.test make arrays kernel fry ;
! Tests ! Tests
[ { } ] [
[
{ 1 10 }
{ 1 10 } [ , "HI" , ] each-line
] { } make
] unit-test
[ { 1 "HI" } ] [
[
{ 1 10 }
{ 1 11 } [ , "HI" , ] each-line
] { } make
] unit-test
[ { 1 "HI" 2 "HI" } ] [
[
{ 1 10 }
{ 2 11 } [ , "HI" , ] each-line
] { } make
] unit-test
[ { { t f 1 } { t f 2 } } ] [
[
{ 1 10 } { 2 11 }
t f
'[ [ _ _ ] dip 3array , ] each-line
] { } make
] unit-test
[ { 10 4 } ] [ { "a" } { 10 3 } text+loc ] unit-test [ { 10 4 } ] [ { "a" } { 10 3 } text+loc ] unit-test
[ { 10 4 } ] [ { "a" } { 10 3 } text+loc ] unit-test [ { 10 4 } ] [ { "a" } { 10 3 } text+loc ] unit-test

View File

@ -1,8 +1,8 @@
! Copyright (C) 2006, 2007 Slava Pestov ! Copyright (C) 2006, 2008 Slava Pestov
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays io kernel math models namespaces make USING: accessors arrays io kernel math models namespaces make
sequences strings splitting combinators unicode.categories sequences strings splitting combinators unicode.categories
math.order ; math.order math.ranges ;
IN: documents IN: documents
: +col ( loc n -- newloc ) [ first2 ] dip + 2array ; : +col ( loc n -- newloc ) [ first2 ] dip + 2array ;
@ -47,7 +47,7 @@ TUPLE: document < model locs ;
2over = [ 2over = [
3drop 3drop
] [ ] [
[ [ first ] bi@ 1+ dup <slice> ] dip each [ [ first ] bi@ [a,b] ] dip each
] if ; inline ] if ; inline
: start/end-on-line ( from to line# -- n1 n2 ) : start/end-on-line ( from to line# -- n1 n2 )