]> gitweb.factorcode.org Git - factor.git/commitdiff
git: better use assert= than custom error + test
authorBjörn Lindqvist <bjourne@gmail.com>
Tue, 6 Feb 2018 03:44:09 +0000 (04:44 +0100)
committerBjörn Lindqvist <bjourne@gmail.com>
Tue, 6 Feb 2018 05:16:29 +0000 (06:16 +0100)
extra/git/git-tests.factor
extra/git/git.factor

index 5022df4ba4ec685f41383566128d3b59c944ee81..e36464fd306213402060564d805290510498e56c 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2015 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: fry git io io.directories io.encodings.utf8 io.files.temp
-io.files.unique io.launcher kernel sequences tools.test ;
+USING: accessors fry git io io.directories io.encodings.utf8
+io.launcher io.streams.string kernel sequences tools.test ;
 IN: git.tests
 
 : run-process-stdout ( process -- string )
@@ -21,6 +21,12 @@ IN: git.tests
         @
     ] with-empty-test-git-repo ; inline
 
+{ "hello" } [
+    commit new "author" "hello\r\n"
+    [ parse-commit-field ] with-string-reader
+    author>>
+] unit-test
+
 { "refs/heads/master" } [
     [ git-head-ref ] with-empty-test-git-repo
 ] unit-test
index b395849bba82a032704d058f51973427123a031e..90828b71945ea06f7790d2cd3eeed5897e50bda3 100644 (file)
@@ -148,11 +148,6 @@ CONSTRUCTOR: <tree> tree ( -- obj ) ;
 
 ERROR: unknown-commit-line line name ;
 
-ERROR: string-expected got expected ;
-
-: expect-string ( string expected -- )
-    2dup = [ 2drop ] [ string-expected ] if ;
-
 ERROR: eof-too-early ;
 ERROR: unknown-field field ;
 
@@ -175,13 +170,11 @@ ERROR: unexpected-text text ;
     } case ;
 
 : parse-commit ( bytes -- commit )
-    " " split1 [ "commit" expect-string ] [ string>number read ] bi*
+    " " split1 [ "commit" assert= ] [ string>number read ] bi*
     utf8 [
         commit new parse-commit-lines
     ] with-byte-reader ;
 
-
-
 : parse-tree-field ( obj parameter -- obj )
     [ "\r\n" read-until* ] dip {
         { "tree" [ >>tree ] }
@@ -504,8 +497,6 @@ ERROR: repeated-parent-hash hash ;
     H{ } clone parents [
         git-head-object [
             parents>> dup string? [ random ] unless [
-                ! [ parents get 2dup key? [ repeated-parent-hash ] when dupd set-at ] keep
-                ! dup "parent: " prepend print flush yield
                 dup git-unpacked-object-exists?
                 [ git-read-object ] [ git-object-from-pack ] if
             ] [ f ] if*