]> gitweb.factorcode.org Git - factor.git/commitdiff
prettyprint: add an unsupported-number-base error.
authorJohn Benediktsson <mrjbq7@gmail.com>
Wed, 30 Mar 2016 21:55:11 +0000 (14:55 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Wed, 30 Mar 2016 21:55:11 +0000 (14:55 -0700)
basis/prettyprint/backend/backend.factor
basis/prettyprint/prettyprint-tests.factor

index ea6db5329091e3cb089c5bfb4bcdc15df65d92ad..b8a602432bbc69c1191b2de6aab46f8fab681afb 100644 (file)
@@ -70,12 +70,15 @@ M: method pprint*
     [ [ neg ] [ call ] [ prepend ] tri* "-" prepend text ]
     [ [ call ] [ prepend ] bi* text ] if ; inline
 
+ERROR: unsupported-number-base n base ;
+
 M: real pprint*
     number-base get {
+        { 10 [ number>string text ] }
         { 16 [ [ >hex ] "0x" pprint-prefixed-number ] }
         {  8 [ [ >oct ] "0o" pprint-prefixed-number ] }
         {  2 [ [ >bin ] "0b" pprint-prefixed-number ] }
-        [ drop number>string text ]
+        [ unsupported-number-base ]
     } case ;
 
 M: float pprint*
@@ -83,8 +86,9 @@ M: float pprint*
         \ NAN: [ fp-nan-payload >hex text ] pprint-prefix
     ] [
         number-base get {
+            { 10 [ number>string text ] }
             { 16 [ [ >hex ] "0x" pprint-prefixed-number ] }
-            [ drop number>string text ]
+            [ unsupported-number-base ]
         } case
     ] if ;
 
index 89f126eaecc7b5a44d69afc937a7835d97d1a575..8ba11bdf76ddb9afd085aae5c8a1f5d0c8e1d800 100644 (file)
@@ -2,7 +2,7 @@ USING: accessors arrays classes.intersection classes.maybe
 classes.union compiler.units continuations definitions effects
 eval generic generic.standard hashtables io io.streams.duplex
 io.streams.string kernel listener make math namespaces parser
-prettyprint prettyprint.config prettyprint.private
+prettyprint prettyprint.backend prettyprint.config prettyprint.private
 prettyprint.sections see sequences splitting
 strings tools.continuations tools.continuations.private
 tools.test vectors vocabs.parser words ;
@@ -15,8 +15,8 @@ IN: prettyprint.tests
 { "0x1000" } [ 16 number-base [ 4096 unparse ] with-variable ] unit-test
 { "1.0" } [ 1.0 unparse ] unit-test
 { "8.0" } [ 8.0 unparse ] unit-test
-{ "8.0" } [ 2 number-base [ 8.0 unparse ] with-variable ] unit-test
-{ "8.0" } [ 8 number-base [ 8.0 unparse ] with-variable ] unit-test
+[ 2 number-base [ 8.0 unparse ] with-variable ] [ unsupported-number-base? ] must-fail-with
+[ 8 number-base [ 8.0 unparse ] with-variable ] [ unsupported-number-base? ] must-fail-with
 { "0x1.0p3" } [ 16 number-base [ 8.0 unparse ] with-variable ] unit-test
 { "1267650600228229401496703205376" } [ 1 100 shift unparse ] unit-test