Skip to content

Commit

Permalink
Change to treat numbers as string values separate and denote as such
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrmurach committed Jul 9, 2019
1 parent aae3a81 commit 3e2bff4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/tty/logger/formatters/text.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Text
SINGLE_QUOTE_REGEX = /'/
ESCAPE_DOUBLE_QUOTE = "\""
ESCAPE_STR_REGEX = /[ ="|{}()\[\]^$+*?.-]/
NUM_REGEX = /^-?\d*(?:\.\d+)?\d+$/

# Dump data in a single formatted line
#
Expand Down Expand Up @@ -99,7 +100,7 @@ def enc_str(str)
case str
when SINGLE_QUOTE_REGEX
str.inspect
when ESCAPE_STR_REGEX, LITERAL_TRUE, LITERAL_FALSE, LITERAL_NULL
when ESCAPE_STR_REGEX, LITERAL_TRUE, LITERAL_FALSE, LITERAL_NULL, NUM_REGEX
ESCAPE_DOUBLE_QUOTE + str.inspect[1..-2] + ESCAPE_DOUBLE_QUOTE
else
str
Expand Down
3 changes: 3 additions & 0 deletions spec/unit/formatters/text_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
{key: "k", value: 1.035, want: "k=1.035"},
{key: "k", value: 1e-5, want: "k=0.00001"},
{key: "k", value: Complex(2,1), want: "k=(2+1i)"},
{key: "k", value: "1", want: "k=\"1\""},
{key: "k", value: "1.035", want: "k=\"1.035\""},
{key: "k", value: "1e-5", want: "k=\"1e-5\""},
{key: "k", value: "v v", want: "k=\"v v\""},
{key: "k", value: " ", want: 'k=" "'},
{key: "k", value: '"', want: 'k="\""'},
Expand Down

0 comments on commit 3e2bff4

Please sign in to comment.