fix nim js cmp fails at CT (#16473)
This commit is contained in:
parent
4cf605dcf6
commit
3f9a2ebea5
4 changed files with 49 additions and 24 deletions
|
|
@ -2394,14 +2394,8 @@ when notJSnotNims:
|
||||||
""".}
|
""".}
|
||||||
|
|
||||||
when defined(js):
|
when defined(js):
|
||||||
when not defined(nimscript):
|
|
||||||
include "system/jssys"
|
include "system/jssys"
|
||||||
include "system/reprjs"
|
include "system/reprjs"
|
||||||
else:
|
|
||||||
proc cmp(x, y: string): int =
|
|
||||||
if x == y: return 0
|
|
||||||
if x < y: return -1
|
|
||||||
return 1
|
|
||||||
|
|
||||||
when defined(js) or defined(nimscript):
|
when defined(js) or defined(nimscript):
|
||||||
proc addInt*(result: var string; x: int64) =
|
proc addInt*(result: var string; x: int64) =
|
||||||
|
|
|
||||||
|
|
@ -340,7 +340,12 @@ proc cmpStrings(a, b: string): int {.asmNoStackFrame, compilerproc.} =
|
||||||
"""
|
"""
|
||||||
|
|
||||||
proc cmp(x, y: string): int =
|
proc cmp(x, y: string): int =
|
||||||
return cmpStrings(x, y)
|
when nimvm:
|
||||||
|
if x == y: result = 0
|
||||||
|
elif x < y: result = -1
|
||||||
|
else: result = 1
|
||||||
|
else:
|
||||||
|
result = cmpStrings(x, y)
|
||||||
|
|
||||||
proc eqStrings(a, b: string): bool {.asmNoStackFrame, compilerproc.} =
|
proc eqStrings(a, b: string): bool {.asmNoStackFrame, compilerproc.} =
|
||||||
asm """
|
asm """
|
||||||
|
|
|
||||||
20
tests/misc/tstrtabs.nim
Normal file
20
tests/misc/tstrtabs.nim
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
discard """
|
||||||
|
targets: "c cpp js"
|
||||||
|
"""
|
||||||
|
|
||||||
|
import std/strtabs
|
||||||
|
|
||||||
|
proc fun()=
|
||||||
|
let ret = newStringTable(modeCaseSensitive)
|
||||||
|
ret["foo"] = "bar"
|
||||||
|
|
||||||
|
doAssert $ret == "{foo: bar}"
|
||||||
|
|
||||||
|
let b = ret["foo"]
|
||||||
|
doAssert b == "bar"
|
||||||
|
|
||||||
|
proc main()=
|
||||||
|
static: fun()
|
||||||
|
fun()
|
||||||
|
|
||||||
|
main()
|
||||||
|
|
@ -1,16 +1,14 @@
|
||||||
discard """
|
discard """
|
||||||
output: '''OK
|
targets: "c cpp js"
|
||||||
@[@[], @[], @[], @[], @[]]
|
|
||||||
'''
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
const characters = "abcdefghijklmnopqrstuvwxyz"
|
const characters = "abcdefghijklmnopqrstuvwxyz"
|
||||||
const numbers = "1234567890"
|
const numbers = "1234567890"
|
||||||
|
|
||||||
var s: string
|
|
||||||
|
|
||||||
proc test_string_slice() =
|
proc test_string_slice() =
|
||||||
# test "slice of length == len(characters)":
|
# test "slice of length == len(characters)":
|
||||||
# replace characters completely by numbers
|
# replace characters completely by numbers
|
||||||
|
var s: string
|
||||||
s = characters
|
s = characters
|
||||||
s[0..^1] = numbers
|
s[0..^1] = numbers
|
||||||
doAssert s == numbers
|
doAssert s == numbers
|
||||||
|
|
@ -51,11 +49,13 @@ proc test_string_slice() =
|
||||||
s[2..0] = numbers
|
s[2..0] = numbers
|
||||||
doAssert s == "ab1234567890cdefghijklmnopqrstuvwxyz"
|
doAssert s == "ab1234567890cdefghijklmnopqrstuvwxyz"
|
||||||
|
|
||||||
|
when nimvm:
|
||||||
|
discard
|
||||||
|
else:
|
||||||
# bug #6223
|
# bug #6223
|
||||||
doAssertRaises(IndexDefect):
|
doAssertRaises(IndexDefect):
|
||||||
discard s[0..999]
|
discard s[0..999]
|
||||||
|
|
||||||
echo("OK")
|
|
||||||
|
|
||||||
proc test_string_cmp() =
|
proc test_string_cmp() =
|
||||||
let world = "hello\0world"
|
let world = "hello\0world"
|
||||||
|
|
@ -76,9 +76,6 @@ proc test_string_cmp() =
|
||||||
doAssert cmp(world, hello) > 0
|
doAssert cmp(world, hello) > 0
|
||||||
doAssert cmp(world, goodbye) > 0
|
doAssert cmp(world, goodbye) > 0
|
||||||
|
|
||||||
test_string_slice()
|
|
||||||
test_string_cmp()
|
|
||||||
|
|
||||||
|
|
||||||
#--------------------------
|
#--------------------------
|
||||||
# bug #7816
|
# bug #7816
|
||||||
|
|
@ -87,9 +84,9 @@ import sequtils
|
||||||
|
|
||||||
proc tester[T](x: T) =
|
proc tester[T](x: T) =
|
||||||
let test = toSeq(0..4).map(i => newSeq[int]())
|
let test = toSeq(0..4).map(i => newSeq[int]())
|
||||||
echo test
|
doAssert $test == "@[@[], @[], @[], @[], @[]]"
|
||||||
|
|
||||||
|
|
||||||
tester(1)
|
|
||||||
|
|
||||||
# #14497
|
# #14497
|
||||||
func reverse*(a: string): string =
|
func reverse*(a: string): string =
|
||||||
|
|
@ -97,4 +94,13 @@ func reverse*(a: string): string =
|
||||||
for i in 0 ..< a.len div 2:
|
for i in 0 ..< a.len div 2:
|
||||||
swap(result[i], result[^(i + 1)])
|
swap(result[i], result[^(i + 1)])
|
||||||
|
|
||||||
|
|
||||||
|
proc main() =
|
||||||
|
test_string_slice()
|
||||||
|
test_string_cmp()
|
||||||
|
|
||||||
|
tester(1)
|
||||||
doAssert reverse("hello") == "olleh"
|
doAssert reverse("hello") == "olleh"
|
||||||
|
|
||||||
|
static: main()
|
||||||
|
main()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue