From 99804fd054d50721de1568ed7a11f9fd5dcd8fab Mon Sep 17 00:00:00 2001 From: John Benediktsson Date: Wed, 30 Mar 2016 14:55:11 -0700 Subject: [PATCH] prettyprint: add an unsupported-number-base error. --- basis/prettyprint/backend/backend.factor | 8 ++++++-- basis/prettyprint/prettyprint-tests.factor | 6 +++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/basis/prettyprint/backend/backend.factor b/basis/prettyprint/backend/backend.factor index ea6db53290..b8a602432b 100644 --- a/basis/prettyprint/backend/backend.factor +++ b/basis/prettyprint/backend/backend.factor @@ -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 ; diff --git a/basis/prettyprint/prettyprint-tests.factor b/basis/prettyprint/prettyprint-tests.factor index 89f126eaec..8ba11bdf76 100644 --- a/basis/prettyprint/prettyprint-tests.factor +++ b/basis/prettyprint/prettyprint-tests.factor @@ -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