From cb56943f811979473ff6ec9043310cb960f18ef9 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Tue, 2 Dec 2008 20:46:09 -0600 Subject: [PATCH] Clean up each-line combinator a bit, add unit tests --- basis/documents/documents-tests.factor | 31 +++++++++++++++++++++++++- basis/documents/documents.factor | 6 ++--- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/basis/documents/documents-tests.factor b/basis/documents/documents-tests.factor index e09afebfc2..88e471cce1 100644 --- a/basis/documents/documents-tests.factor +++ b/basis/documents/documents-tests.factor @@ -1,8 +1,37 @@ IN: documents.tests -USING: documents namespaces tools.test ; +USING: documents namespaces tools.test make arrays kernel fry ; ! 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 diff --git a/basis/documents/documents.factor b/basis/documents/documents.factor index a82437ba40..6993bcb65b 100644 --- a/basis/documents/documents.factor +++ b/basis/documents/documents.factor @@ -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. USING: accessors arrays io kernel math models namespaces make sequences strings splitting combinators unicode.categories -math.order ; +math.order math.ranges ; IN: documents : +col ( loc n -- newloc ) [ first2 ] dip + 2array ; @@ -47,7 +47,7 @@ TUPLE: document < model locs ; 2over = [ 3drop ] [ - [ [ first ] bi@ 1+ dup ] dip each + [ [ first ] bi@ [a,b] ] dip each ] if ; inline : start/end-on-line ( from to line# -- n1 n2 )