]> gitweb.factorcode.org Git - factor.git/commitdiff
documents.elements: more tests.
authorJohn Benediktsson <mrjbq7@gmail.com>
Wed, 31 Mar 2021 15:37:07 +0000 (08:37 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Wed, 31 Mar 2021 15:37:07 +0000 (08:37 -0700)
basis/documents/elements/elements-tests.factor
basis/documents/elements/elements.factor

index 9a27a7f3b9c3466a70ab968819f55607596675ce..d2de9f0380c26251db6fbc165ceb89930625c68c 100644 (file)
@@ -66,21 +66,22 @@ Sixth line
 
 " doc get set-doc-string
 
+{ { 0 0 } } [ { 0 0 } doc get paragraph-elt prev-elt ] unit-test
 { { 0 0 } } [ { 0 2 } doc get paragraph-elt prev-elt ] unit-test
 { { 0 0 } } [ { 1 2 } doc get paragraph-elt prev-elt ] unit-test
 { { 3 0 } } [ { 5 2 } doc get paragraph-elt prev-elt ] unit-test
+{ { 3 0 } } [ { 6 0 } doc get paragraph-elt prev-elt ] unit-test
+{ { 6 0 } } [ { 7 0 } doc get paragraph-elt prev-elt ] unit-test
+{ { 7 0 } } [ { 8 0 } doc get paragraph-elt prev-elt ] unit-test
 
 { { 1 11 } } [ { 0 3 } doc get paragraph-elt next-elt ] unit-test
 { { 1 11 } } [ { 1 3 } doc get paragraph-elt next-elt ] unit-test
 { { 2 0 } } [ { 1 11 } doc get paragraph-elt next-elt ] unit-test
 { { 5 10 } } [ { 2 0 } doc get paragraph-elt next-elt ] unit-test
 { { 5 10 } } [ { 4 2 } doc get paragraph-elt next-elt ] unit-test
-
-{ { 3 0 } } [ { 6 0 } doc get paragraph-elt prev-elt ] unit-test
-{ { 6 0 } } [ { 7 0 } doc get paragraph-elt prev-elt ] unit-test
-
 { { 7 0 } } [ { 6 0 } doc get paragraph-elt next-elt ] unit-test
 { { 8 0 } } [ { 7 0 } doc get paragraph-elt next-elt ] unit-test
+{ { 8 0 } } [ { 8 0 } doc get paragraph-elt next-elt ] unit-test
 
 
 ! page-elt
index 470ae6da0eee86bb59f7fe5b32535e5c95bdf2c0..853a6e1f14a5ca246e874104070f62af34e571a5 100644 (file)
@@ -113,7 +113,7 @@ M: one-line-elt next-elt
     [ empty? ] find-last-from drop [ 1 + ] [ 0 ] if* :> line#
 
     loc first line# = loc second 0 = and [
-        line# 1 - 0 2array
+        line# 1 [-] 0 2array
     ] [
         line# 0 2array
     ] if ;
@@ -122,11 +122,12 @@ M: one-line-elt next-elt
     loc first 1 + document value>>
     [ empty? ] find-from drop :> line#
 
-    line# document value>> length or 1 [-]
-    dup document doc-line length
-    [ zero? [ 1 + ] when ] keep 2array
-
-    dup loc = [ first 1 + 0 2array ] when ;
+    line# [
+        1 - dup document doc-line length 2array
+        dup loc = [ first 1 + 0 2array ] when
+    ] [
+        document doc-end
+    ] if* ;
 
 PRIVATE>
 
@@ -149,7 +150,7 @@ M: page-elt next-elt
     3dup [ first ] [ last-line# ] [ #lines>> ] tri* - >
     [ drop nip doc-end ] [ nip #lines>> +line ] if ;
 
-CONSTANT: line-elt T{ page-elt f 1 }
+CONSTANT: line-elt T{ page-elt { #lines 1 } }
 
 SINGLETON: doc-elt