Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move rest of tests to testament #16140

Merged
merged 3 commits into from
Nov 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions lib/packages/docutils/rstgen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1364,9 +1364,3 @@ proc rstToLatex*(rstSource: string; options: RstParseOptions): string {.inline,
var rstGenera: RstGenerator
rstGenera.initRstGenerator(outLatex, defaultConfig(), "input", options)
rstGenera.renderRstToOut(rstParse(rstSource, "", 1, 1, option, options), result)


when isMainModule:
assert rstToHtml("*Hello* **world**!", {},
newStringTable(modeStyleInsensitive)) ==
"<em>Hello</em> <strong>world</strong>!"
97 changes: 0 additions & 97 deletions lib/pure/sugar.nim
Original file line number Diff line number Diff line change
Expand Up @@ -363,100 +363,3 @@ macro collect*(init, body: untyped): untyped {.since: (1, 1).} =
for i in 1 ..< init.len:
call.add init[i]
result = newTree(nnkStmtListExpr, newVarStmt(res, call), resBody, res)


when isMainModule:
since (1, 1):
block dup_with_field:
type
Foo = object
col, pos: int
name: string

proc inc_col(foo: var Foo) = inc(foo.col)
proc inc_pos(foo: var Foo) = inc(foo.pos)
proc name_append(foo: var Foo, s: string) = foo.name &= s

let a = Foo(col: 1, pos: 2, name: "foo")
block:
let b = a.dup(inc_col, inc_pos):
_.pos = 3
name_append("bar")
inc_pos

doAssert(b == Foo(col: 2, pos: 4, name: "foobar"))

block:
let b = a.dup(inc_col, pos = 3, name = "bar"):
name_append("bar")
inc_pos

doAssert(b == Foo(col: 2, pos: 4, name: "barbar"))

import algorithm

var a = @[1, 2, 3, 4, 5, 6, 7, 8, 9]
doAssert dup(a, sort(_)) == sorted(a)
doAssert a.dup(sort) == sorted(a)
#Chaining:
var aCopy = a
aCopy.insert(10)
doAssert a.dup(insert(10)).dup(sort()) == sorted(aCopy)

import random

const b = @[0, 1, 2]
let c = b.dup shuffle()
doAssert c[0] == 1
doAssert c[1] == 0

#test collect
import sets, tables

let data = @["bird", "word"] # if this gets stuck in your head, its not my fault
assert collect(newSeq, for (i, d) in data.pairs: (if i mod 2 == 0: d)) == @["bird"]
assert collect(initTable(2), for (i, d) in data.pairs: {i: d}) == {0: "bird",
1: "word"}.toTable
assert initHashSet.collect(for d in data.items: {d}) == data.toHashSet

let x = collect(newSeqOfCap(4)):
for (i, d) in data.pairs:
if i mod 2 == 0: d
assert x == @["bird"]

# bug #12874

let bug1 = collect(
newSeq,
for (i, d) in data.pairs:(
block:
if i mod 2 == 0:
d
else:
d & d
)
)
assert bug1 == @["bird", "wordword"]

import strutils
let y = collect(newSeq):
for (i, d) in data.pairs:
try: parseInt(d) except: 0
assert y == @[0, 0]

let z = collect(newSeq):
for (i, d) in data.pairs:
case d
of "bird": "word"
else: d
assert z == @["word", "word"]


proc tforum =
let ans = collect(newSeq):
for y in 0..10:
if y mod 5 == 2:
for x in 0..y:
x

tforum()
41 changes: 0 additions & 41 deletions lib/std/editdistance.nim
Original file line number Diff line number Diff line change
Expand Up @@ -264,44 +264,3 @@ proc editDistanceAscii*(a, b: string): int {.noSideEffect.} =
if x > c3: x = c3
row[p] = x
result = row[e]


when isMainModule:
doAssert editDistance("", "") == 0
doAssert editDistance("kitten", "sitting") == 3 # from Wikipedia
doAssert editDistance("flaw", "lawn") == 2 # from Wikipedia

doAssert editDistance("привет", "превет") == 1
doAssert editDistance("Åge", "Age") == 1
# editDistance, one string is longer in bytes, but shorter in rune length
# first string: 4 bytes, second: 6 bytes, but only 3 runes
doAssert editDistance("aaaa", "×××") == 4

block veryLongStringEditDistanceTest:
const cap = 256
var
s1 = newStringOfCap(cap)
s2 = newStringOfCap(cap)
while len(s1) < cap:
s1.add 'a'
while len(s2) < cap:
s2.add 'b'
doAssert editDistance(s1, s2) == cap

block combiningCodePointsEditDistanceTest:
const s = "A\xCC\x8Age"
doAssert editDistance(s, "Age") == 1

doAssert editDistanceAscii("", "") == 0
doAssert editDistanceAscii("kitten", "sitting") == 3 # from Wikipedia
doAssert editDistanceAscii("flaw", "lawn") == 2 # from Wikipedia


assert(editDistance("prefix__hallo_suffix", "prefix__hallo_suffix") == 0)
assert(editDistance("prefix__hallo_suffix", "prefix__hallo_suffi1") == 1)
assert(editDistance("prefix__hallo_suffix", "prefix__HALLO_suffix") == 5)
assert(editDistance("prefix__hallo_suffix", "prefix__ha_suffix") == 3)
assert(editDistance("prefix__hallo_suffix", "prefix") == 14)
assert(editDistance("prefix__hallo_suffix", "suffix") == 14)
assert(editDistance("prefix__hallo_suffix", "prefix__hao_suffix") == 2)
assert(editDistance("main", "malign") == 2)
24 changes: 0 additions & 24 deletions lib/std/sums.nim
Original file line number Diff line number Diff line change
Expand Up @@ -60,27 +60,3 @@ runnableExamples:
const data = [1, 2, 3, 4, 5, 6, 7, 8, 9]
doAssert sumKbn(data) == 45
doAssert sumPairs(data) == 45


when isMainModule:
from math import pow

var epsilon = 1.0
while 1.0 + epsilon != 1.0:
epsilon /= 2.0
let data = @[1.0, epsilon, -epsilon]
assert sumKbn(data) == 1.0
assert sumPairs(data) != 1.0 # known to fail
assert (1.0 + epsilon) - epsilon != 1.0

var tc1: seq[float]
for n in 1 .. 1000:
tc1.add 1.0 / n.float
assert sumKbn(tc1) == 7.485470860550345
assert sumPairs(tc1) == 7.485470860550345

var tc2: seq[float]
for n in 1 .. 1000:
tc2.add pow(-1.0, n.float) / n.float
assert sumKbn(tc2) == -0.6926474305598203
assert sumPairs(tc2) == -0.6926474305598204
20 changes: 0 additions & 20 deletions lib/std/with.nim
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,3 @@ macro with*(arg: typed; calls: varargs[untyped]): untyped =

result = newNimNode(nnkStmtList, arg)
underscoredCalls(result, calls, arg)

when isMainModule:
type
Foo = object
col, pos: string
name: string

proc setColor(f: var Foo; r, g, b: int) = f.col = $(r, g, b)
proc setPosition(f: var Foo; x, y: float) = f.pos = $(x, y)

var f: Foo
with(f, setColor(2, 3, 4), setPosition(0.0, 1.0))
echo f

f = Foo()
with f:
col = $(2, 3, 4)
pos = $(0.0, 1.0)
_.name = "bar"
echo f
44 changes: 0 additions & 44 deletions lib/std/wordwrap.nim
Original file line number Diff line number Diff line change
Expand Up @@ -72,47 +72,3 @@ proc wrapWords*(s: string, maxLineWidth = 80,
for k in i..<j: result.add(s[k])
#lastSep.setLen(0)
i = j

when isMainModule:

when true:
let
inp = """ this is a long text -- muchlongerthan10chars and here
it goes"""
outp = " this is a\nlong text\n--\nmuchlongerthan10chars\nand here\nit goes"
doAssert wrapWords(inp, 10, false) == outp

let
longInp = """ThisIsOneVeryLongStringWhichWeWillSplitIntoEightSeparatePartsNow"""
longOutp = "ThisIsOn\neVeryLon\ngStringW\nhichWeWi\nllSplitI\nntoEight\nSeparate\nPartsNow"
doAssert wrapWords(longInp, 8, true) == longOutp

# test we don't break Umlauts into invalid bytes:
let fies = "äöüöäöüöäöüöäöüööäöüöäößßßßüöäößßßßßß"
let fiesRes = "ä\nö\nü\nö\nä\nö\nü\nö\nä\nö\nü\nö\nä\nö\nü\nö\nö\nä\nö\nü\nö\nä\nö\nß\nß\nß\nß\nü\nö\nä\nö\nß\nß\nß\nß\nß\nß"
doAssert wrapWords(fies, 1, true) == fiesRes

let longlongword = """abc uitdaeröägfßhydüäpydqfü,träpydqgpmüdträpydföägpydörztdüöäfguiaeowäzjdtrüöäp psnrtuiydrözenrüöäpyfdqazpesnrtulocjtüö
äzydgyqgfqfgprtnwjlcydkqgfüöezmäzydydqüüöäpdtrnvwfhgckdumböäpydfgtdgfhtdrntdrntydfogiayqfguiatrnydrntüöärtniaoeydfgaoeiqfglwcßqfgxvlcwgtfhiaoen
rsüöäapmböäptdrniaoydfglckqfhouenrtsüöäptrniaoeyqfgulocfqclgwxßqflgcwßqfxglcwrniatrnmüböäpmöäbpümöäbpüöämpbaoestnriaesnrtdiaesrtdniaesdrtnaetdr
iaoenvlcyfglwckßqfgvwkßqgfvlwkßqfgvlwckßqvlwkgfUIαοιαοιαχολωχσωχνωκψρχκψρτιεαοσηζϵηζιοεννκεωνιαλωσωκνκψρκγτφγτχκγτεκργτιχνκιωχσιλωσλωχξλξλξωχωχ
ξχλωωχαοεοιαεοαεοιαεοαεοιαοεσναοεκνρκψγκψφϵιηαααοε"""
let longlongwordRes = """
abc uitdaeröägfßhydüäpydqfü,träpydqgpmüdträpydföägpydörztdüöäfguiaeowäzjdtrüöäp
psnrtuiydrözenrüöäpyfdqazpesnrtulocjtüöäzydgyqgfqfgprtnwjlcydkqgfüöezmäzydydqüü
öäpdtrnvwfhgckdumböäpydfgtdgfhtdrntdrntydfogiayqfguiatrnydrntüöärtniaoeydfgaoeiq
fglwcßqfgxvlcwgtfhiaoenrsüöäapmböäptdrniaoydfglckqfhouenrtsüöäptrniaoeyqfgulocf
qclgwxßqflgcwßqfxglcwrniatrnmüböäpmöäbpümöäbpüöämpbaoestnriaesnrtdiaesrtdniaesdr
tnaetdriaoenvlcyfglwckßqfgvwkßqgfvlwkßqfgvlwckßqvlwkgfUIαοιαοιαχολωχσωχνωκψρχκψ
ρτιεαοσηζϵηζιοεννκεωνιαλωσωκνκψρκγτφγτχκγτεκργτιχνκιωχσιλωσλωχξλξλξωχωχ
ξχλωωχαοεοιαεοαεοιαεοαεοιαοεσναοεκνρκψγκψφϵιηαααοε"""
doAssert wrapWords(longlongword) == longlongwordRes

# bug #14579
const input60 = """
This string is wrapped to 60 characters. If we call
wrapwords on it it will be re-wrapped to 80 characters.
"""
const input60Res = """This string is wrapped to 60 characters. If we call wrapwords on it it will be
re-wrapped to 80 characters."""
doAssert wrapWords(input60) == input60Res
40 changes: 40 additions & 0 deletions tests/stdlib/teditdistance.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import std/editdistance

doAssert editDistance("", "") == 0
doAssert editDistance("kitten", "sitting") == 3 # from Wikipedia
doAssert editDistance("flaw", "lawn") == 2 # from Wikipedia

doAssert editDistance("привет", "превет") == 1
doAssert editDistance("Åge", "Age") == 1
# editDistance, one string is longer in bytes, but shorter in rune length
# first string: 4 bytes, second: 6 bytes, but only 3 runes
doAssert editDistance("aaaa", "×××") == 4

block veryLongStringEditDistanceTest:
const cap = 256
var
s1 = newStringOfCap(cap)
s2 = newStringOfCap(cap)
while len(s1) < cap:
s1.add 'a'
while len(s2) < cap:
s2.add 'b'
doAssert editDistance(s1, s2) == cap

block combiningCodePointsEditDistanceTest:
const s = "A\xCC\x8Age"
doAssert editDistance(s, "Age") == 1

doAssert editDistanceAscii("", "") == 0
doAssert editDistanceAscii("kitten", "sitting") == 3 # from Wikipedia
doAssert editDistanceAscii("flaw", "lawn") == 2 # from Wikipedia


assert(editDistance("prefix__hallo_suffix", "prefix__hallo_suffix") == 0)
assert(editDistance("prefix__hallo_suffix", "prefix__hallo_suffi1") == 1)
assert(editDistance("prefix__hallo_suffix", "prefix__HALLO_suffix") == 5)
assert(editDistance("prefix__hallo_suffix", "prefix__ha_suffix") == 3)
assert(editDistance("prefix__hallo_suffix", "prefix") == 14)
assert(editDistance("prefix__hallo_suffix", "suffix") == 14)
assert(editDistance("prefix__hallo_suffix", "prefix__hao_suffix") == 2)
assert(editDistance("main", "malign") == 2)
7 changes: 6 additions & 1 deletion tests/stdlib/trstgen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ outputsub: ""

import ../../lib/packages/docutils/rstgen
import ../../lib/packages/docutils/rst
import unittest
import unittest, strtabs

suite "YAML syntax highlighting":
test "Basics":
Expand Down Expand Up @@ -177,3 +177,8 @@ not in table"""
let output2 = rstToHtml(input2, {roSupportMarkdown}, defaultConfig())
assert output2 == """<table border="1" class="docutils"><tr><th>A1 header</th><th>A2</th></tr>
</table>"""


assert rstToHtml("*Hello* **world**!", {},
newStringTable(modeStyleInsensitive)) ==
"<em>Hello</em> <strong>world</strong>!"
Loading