Skip to content

Commit 69ec1d9

Browse files
committed
Tests for numeric constants and dots
1 parent 7f49614 commit 69ec1d9

File tree

1 file changed

+44
-16
lines changed

1 file changed

+44
-16
lines changed

test/tokenize.jl

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ end
419419
@testset "interpolation" begin
420420
@testset "basic" begin
421421
str = "\"\$x \$y\""
422-
ts = collect(tokenize(str))
422+
ts = collect(tokenize(str))
423423
@test ts[1] ~ (K"\"" , "\"", str)
424424
@test ts[2] ~ (K"$" , "\$", str)
425425
@test ts[3] ~ (K"Identifier" , "x" , str)
@@ -461,7 +461,7 @@ end
461461

462462
@testset "duplicate \$" begin
463463
str = "\"\$\$\""
464-
ts = collect(tokenize(str))
464+
ts = collect(tokenize(str))
465465
@test ts[1] ~ (K"\"" , "\"", str)
466466
@test ts[2] ~ (K"$" , "\$", str)
467467
@test ts[3] ~ (K"$" , "\$", str)
@@ -472,7 +472,7 @@ end
472472
@testset "Unmatched parens" begin
473473
# issue 73: https://github.com/JuliaLang/Tokenize.jl/issues/73
474474
str = "\"\$(fdsf\""
475-
ts = collect(tokenize(str))
475+
ts = collect(tokenize(str))
476476
@test ts[1] ~ (K"\"" , "\"" , str)
477477
@test ts[2] ~ (K"$" , "\$" , str)
478478
@test ts[3] ~ (K"(" , "(" , str)
@@ -484,7 +484,7 @@ end
484484
@testset "Unicode" begin
485485
# issue 178: https://github.com/JuliaLang/Tokenize.jl/issues/178
486486
str = """ "\$uₕx \$(uₕx - ux)" """
487-
ts = collect(tokenize(str))
487+
ts = collect(tokenize(str))
488488
@test ts[ 1] ~ (K"Whitespace" , " " , str)
489489
@test ts[ 2] ~ (K"\"" , "\"" , str)
490490
@test ts[ 3] ~ (K"$" , "\$" , str)
@@ -505,7 +505,7 @@ end
505505

506506
@testset "var\"...\" disabled in interpolations" begin
507507
str = """ "\$var"x" " """
508-
ts = collect(tokenize(str))
508+
ts = collect(tokenize(str))
509509
@test ts[ 1] ~ (K"Whitespace" , " " , str)
510510
@test ts[ 2] ~ (K"\"" , "\"" , str)
511511
@test ts[ 3] ~ (K"$" , "\$" , str)
@@ -519,14 +519,30 @@ end
519519
@test ts[11] ~ (K"EndMarker" , "" , str)
520520
end
521521

522-
@testset "invalid chars after identifier" begin
523-
str = """ "\$x෴" """
524-
ts = collect(tokenize(str))
525-
@test ts[4] ~ (K"Identifier" , "x" , str)
526-
@test ts[5] ~ (K"ErrorInvalidInterpolationTerminator" , "" , str)
527-
@test ts[6] ~ (K"String" , "" , str)
528-
@test is_error(ts[5].kind)
529-
@test ts[5].kind == K"ErrorInvalidInterpolationTerminator"
522+
@testset "chars after interpolation identifier" begin
523+
# Operators allowed
524+
@test toks("\"\$x?\"") == [
525+
"\""=>K"\""
526+
"\$"=>K"$"
527+
"x"=>K"Identifier"
528+
"?"=>K"String"
529+
"\""=>K"\""
530+
]
531+
@test toks("\"\$x⫪\"") == [
532+
"\""=>K"\""
533+
"\$"=>K"$"
534+
"x"=>K"Identifier"
535+
""=>K"String"
536+
"\""=>K"\""
537+
]
538+
# Some chars disallowed (eg, U+0DF4)
539+
@test toks("\"\$x෴\"") == [
540+
"\""=>K"\""
541+
"\$"=>K"$"
542+
"x"=>K"Identifier"
543+
""=>K"ErrorInvalidInterpolationTerminator"
544+
"\""=>K"\""
545+
]
530546
end
531547
end
532548

@@ -635,8 +651,6 @@ end
635651
@test toks("3e2_2") == ["3e2"=>K"Float", "_2"=>K"Identifier"]
636652
@test toks("1e") == ["1"=>K"Integer", "e"=>K"Identifier"]
637653

638-
@test toks("1.:0") == ["1."=>K"Float", ":"=>K":", "0"=>K"Integer"]
639-
640654
# Floating point with \minus rather than -
641655
@test onlytok("1.0e−0") == K"Float"
642656
@test onlytok("1.0f−0") == K"Float32"
@@ -681,11 +695,23 @@ end
681695
"f"=>K"Identifier", "("=>K"(", "a"=>K"Identifier", ")"=>K")"]
682696
@test toks("1f0./1") == ["1f0"=>K"Float32", "./"=>K"/", "1"=>K"Integer"]
683697

698+
# Dotted operators after numeric constants are ok
699+
@test toks("1e1.⫪") == ["1e1"=>K"Float", ".⫪"=>K""]
700+
@test toks("1.1.⫪") == ["1.1"=>K"Float", ".⫪"=>K""]
701+
@test toks("1e1.−") == ["1e1"=>K"Float", ".−"=>K"-"]
702+
@test toks("1.1.−") == ["1.1"=>K"Float", ".−"=>K"-"]
703+
# Non-dottable operators are not ok
704+
@test toks("1e1.\$") == ["1e1."=>K"ErrorInvalidNumericConstant", "\$"=>K"$"]
705+
@test toks("1.1.\$") == ["1.1."=>K"ErrorInvalidNumericConstant", "\$"=>K"$"]
706+
684707
# Ambiguous dotted operators
685708
@test toks("1.+") == ["1."=>K"ErrorAmbiguousNumericConstant", "+"=>K"+"]
686709
@test toks("1.+ ") == ["1."=>K"ErrorAmbiguousNumericConstant", "+"=>K"+", " "=>K"Whitespace"]
687710
@test toks("1.⤋") == ["1."=>K"ErrorAmbiguousNumericConstant", ""=>K""]
688-
@test toks("1.?") == ["1."=>K"ErrorAmbiguousNumericConstant", "?"=>K"?"]
711+
@test toks("1.⫪") == ["1."=>K"ErrorAmbiguousNumericConstant", ""=>K""]
712+
# non-dottable ops are the exception
713+
@test toks("1.:") == ["1."=>K"Float", ":"=>K":"]
714+
@test toks("1.\$") == ["1."=>K"Float", "\$"=>K"$"]
689715

690716
# Ambiguous - literal vs multiply by juxtaposition
691717
@test toks("1.x") == ["1."=>K"ErrorAmbiguousNumericDotMultiply", "x"=>K"Identifier"]
@@ -846,6 +872,8 @@ end
846872
raw"^ ↑ ↓ ⇵ ⟰ ⟱ ⤈ ⤉ ⤊ ⤋ ⤒ ⤓ ⥉ ⥌ ⥍ ⥏ ⥑ ⥔ ⥕ ⥘ ⥙ ⥜ ⥝ ⥠ ⥡ ⥣ ⥥ ⥮ ⥯ ↑ ↓"
847873
raw"::"
848874
raw"."
875+
"⫪ ⫫"
876+
"\u00b7 \u0387"
849877
]
850878
if VERSION >= v"1.6.0"
851879
push!(ops, raw"<-- <-->")

0 commit comments

Comments
 (0)