From aa407d1016134833da0dd478e3421c62b4caab07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Lindqvist?= Date: Tue, 6 Feb 2018 04:44:09 +0100 Subject: [PATCH] git: better use assert= than custom error + test --- extra/git/git-tests.factor | 10 ++++++++-- extra/git/git.factor | 11 +---------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/extra/git/git-tests.factor b/extra/git/git-tests.factor index 5022df4ba4..e36464fd30 100644 --- a/extra/git/git-tests.factor +++ b/extra/git/git-tests.factor @@ -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 diff --git a/extra/git/git.factor b/extra/git/git.factor index b395849bba..90828b7194 100644 --- a/extra/git/git.factor +++ b/extra/git/git.factor @@ -148,11 +148,6 @@ CONSTRUCTOR: 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*