Merge remote-tracking branch 'upstream/devel' into b10

This commit is contained in:
flywind
2021-03-29 10:35:17 +08:00
80 changed files with 1664 additions and 989 deletions

View File

@@ -7,68 +7,88 @@ import std/[isolation, json]
proc main() =
proc main(moveZeroesOut: static bool) =
block:
type
Empty = ref object
var x = isolate(Empty())
discard extract(x)
block: # string literals
var data = isolate("string")
doAssert data.extract == "string"
doAssert data.extract == ""
if moveZeroesOut:
doAssert data.extract == ""
block: # string literals
var data = isolate("")
doAssert data.extract == ""
doAssert data.extract == ""
if moveZeroesOut:
doAssert data.extract == ""
block:
var src = "string"
var data = isolate(move src)
doAssert data.extract == "string"
doAssert src.len == 0
if moveZeroesOut:
doAssert src.len == 0
block: # int literals
var data = isolate(1)
doAssert data.extract == 1
doAssert data.extract == 0
if moveZeroesOut:
doAssert data.extract == 0
block: # float literals
var data = isolate(1.6)
doAssert data.extract == 1.6
doAssert data.extract == 0.0
if moveZeroesOut:
doAssert data.extract == 0.0
block:
var data = isolate(@["1", "2"])
doAssert data.extract == @["1", "2"]
doAssert data.extract == @[]
if moveZeroesOut:
doAssert data.extract == @[]
block:
var data = isolate(@["1", "2", "3", "4", "5"])
doAssert data.extract == @["1", "2", "3", "4", "5"]
doAssert data.extract == @[]
if moveZeroesOut:
doAssert data.extract == @[]
block:
var data = isolate(@["", ""])
doAssert data.extract == @["", ""]
doAssert data.extract == @[]
if moveZeroesOut:
doAssert data.extract == @[]
block:
var src = @["1", "2"]
var data = isolate(move src)
doAssert data.extract == @["1", "2"]
doAssert src.len == 0
if moveZeroesOut:
doAssert src.len == 0
block:
var data = isolate(@[1, 2])
doAssert data.extract == @[1, 2]
doAssert data.extract == @[]
if moveZeroesOut:
doAssert data.extract == @[]
block:
var data = isolate(["1", "2"])
doAssert data.extract == ["1", "2"]
doAssert data.extract == ["", ""]
if moveZeroesOut:
doAssert data.extract == ["", ""]
block:
var data = isolate([1, 2])
doAssert data.extract == [1, 2]
doAssert data.extract == [0, 0]
if moveZeroesOut:
doAssert data.extract == [0, 0]
block:
type
@@ -111,5 +131,5 @@ proc main() =
doAssert $x == """@[(value: "1234")]"""
static: main()
main()
static: main(moveZeroesOut = false)
main(moveZeroesOut = true)

View File

@@ -300,3 +300,14 @@ block: # bug #17383
when not defined(js):
testRoundtrip(int64.high): "9223372036854775807"
testRoundtrip(uint64.high): "18446744073709551615"
block:
let a = "18446744073709551615"
let b = a.parseJson
doAssert b.kind == JString
let c = $b
when defined(js):
doAssert c == "18446744073709552000"
else:
doAssert c == "18446744073709551615"

View File

@@ -71,7 +71,7 @@ template fn() =
block:
let a = (int32.high, uint32.high)
testRoundtrip(a): "[2147483647,4294967295]"
when not defined(js):
when int.sizeof > 4:
block:
let a = (int64.high, uint64.high)
testRoundtrip(a): "[9223372036854775807,18446744073709551615]"

View File

@@ -17,10 +17,11 @@ proc test() =
wrapSocket(ctx, socket)
# trying 2 sites makes it more resilent: refs #17458 this could give:
# Error: unhandled exception: Call to 'connect' timed out. [TimeoutError]
# * Call to 'connect' timed out. [TimeoutError]
# * No route to host [OSError]
try:
fn("www.nim-lang.org")
except TimeoutError:
except TimeoutError, OSError:
fn("www.google.com")
test()

View File

@@ -2,7 +2,7 @@ discard """
targets: "c js"
"""
import parsecfg, streams
import parsecfg, streams, sequtils
when not defined(js):
from stdtest/specialpaths import buildDir
@@ -39,19 +39,14 @@ var ss = newStringStream()
dict1.writeConfig(ss)
## Reading a configuration file.
var dict2 = loadConfig(newStringStream(ss.data))
var charset = dict2.getSectionValue("", "charset")
var threads = dict2.getSectionValue("Package", "--threads")
var pname = dict2.getSectionValue("Package", "name")
var name = dict2.getSectionValue("Author", "name")
var qq = dict2.getSectionValue("Author", "qq")
var email = dict2.getSectionValue("Author", "email")
doAssert charset == "utf-8"
doAssert threads == "on"
doAssert pname == "hello"
doAssert name == "lihf8515"
doAssert qq == "10214028"
doAssert email == "lihaifeng@wxm.com"
let dict2 = loadConfig(newStringStream(ss.data))
doAssert dict2.getSectionValue("", "charset") == "utf-8"
doAssert dict2.getSectionValue("Package", "--threads") == "on"
doAssert dict2.getSectionValue("Package", "name") == "hello"
doAssert dict2.getSectionValue("Author", "name") == "lihf8515"
doAssert dict2.getSectionValue("Author", "qq") == "10214028"
doAssert dict2.getSectionValue("Author", "email") == "lihaifeng@wxm.com"
doAssert toSeq(dict2.sections) == @["", "Package", "Author"]
## Modifying a configuration file.
var dict3 = loadConfig(newStringStream(ss.data))

View File

@@ -196,9 +196,15 @@ suite "RST/Markdown general":
| | F2 without pipe
not in table"""
let output1 = input1.toHtml
doAssert output1 == """<table border="1" class="docutils"><tr><th>A1 header</th><th>A2 | not fooled</th></tr>
#[
TODO: `\|` inside a table cell should render as `|`
`|` outside a table cell should render as `\|`
consistently with markdown, see https://stackoverflow.com/a/66557930/1426932
]#
doAssert output1 == """
<table border="1" class="docutils"><tr><th>A1 header</th><th>A2 | not fooled</th></tr>
<tr><td>C1</td><td>C2 <strong>bold</strong></td></tr>
<tr><td>D1 <tt class="docutils literal"><span class="pre">code |</span></tt></td><td>D2</td></tr>
<tr><td>D1 <tt class="docutils literal"><span class="pre">code \|</span></tt></td><td>D2</td></tr>
<tr><td>E1 | text</td><td></td></tr>
<tr><td></td><td>F2 without pipe</td></tr>
</table><p>not in table</p>
@@ -549,6 +555,18 @@ let x = 1
let output2 = input2.toHtml
doAssert "<pre" in output2 and "class=\"Keyword\"" in output2
test "interpreted text":
check """`foo.bar`""".toHtml == """<tt class="docutils literal"><span class="pre">foo.bar</span></tt>"""
check """`foo\`\`bar`""".toHtml == """<tt class="docutils literal"><span class="pre">foo``bar</span></tt>"""
check """`foo\`bar`""".toHtml == """<tt class="docutils literal"><span class="pre">foo`bar</span></tt>"""
check """`\`bar`""".toHtml == """<tt class="docutils literal"><span class="pre">`bar</span></tt>"""
check """`a\b\x\\ar`""".toHtml == """<tt class="docutils literal"><span class="pre">a\b\x\\ar</span></tt>"""
test "inline literal":
check """``foo.bar``""".toHtml == """<tt class="docutils literal"><span class="pre">foo.bar</span></tt>"""
check """``foo\bar``""".toHtml == """<tt class="docutils literal"><span class="pre">foo\bar</span></tt>"""
check """``f\`o\\o\b`ar``""".toHtml == """<tt class="docutils literal"><span class="pre">f\`o\\o\b`ar</span></tt>"""
test "RST comments":
let input1 = """
Check that comment disappears:
@@ -1259,6 +1277,55 @@ Test1
let refline = "Ref. " & ref1 & "! and " & ref2 & ";and " & ref3 & "."
doAssert refline in output1
test "Option lists 1":
# check that "* b" is not consumed by previous bullet item because of
# incorrect indentation handling in option lists
let input = dedent """
* a
-m desc
-n very long
desc
* b"""
let output = input.toHtml
check(output.count("<ul") == 1)
check(output.count("<li>") == 2)
check(output.count("<table") == 1)
check("""<th align="left">-m</th><td align="left">desc</td>""" in output)
check("""<th align="left">-n</th><td align="left">very long desc</td>""" in
output)
test "Option lists 2":
# check that 2nd option list is not united with the 1st
let input = dedent """
* a
-m desc
-n very long
desc
-d option"""
let output = input.toHtml
check(output.count("<ul") == 1)
check(output.count("<table") == 2)
check("""<th align="left">-m</th><td align="left">desc</td>""" in output)
check("""<th align="left">-n</th><td align="left">very long desc</td>""" in
output)
check("""<th align="left">-d</th><td align="left">option</td>""" in
output)
test "Option list 3 (double /)":
let input = dedent """
* a
//compile compile1
//doc doc1
cont
-d option"""
let output = input.toHtml
check(output.count("<ul") == 1)
check(output.count("<table") == 2)
check("""<th align="left">compile</th><td align="left">compile1</td>""" in output)
check("""<th align="left">doc</th><td align="left">doc1 cont</td>""" in
output)
check("""<th align="left">-d</th><td align="left">option</td>""" in
output)
suite "RST/Code highlight":
test "Basic Python code highlight":
let pythonCode = """