From cc3c03ae72a0ab7144067c919ca78e0e46e7224a Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Tue, 2 Mar 2021 03:53:05 -0800 Subject: [PATCH] re-enable disabled tests after #17173 (#17228) --- tests/stdlib/tstrbasics.nim | 186 +++++++++++++++--------------------- 1 file changed, 75 insertions(+), 111 deletions(-) diff --git a/tests/stdlib/tstrbasics.nim b/tests/stdlib/tstrbasics.nim index 8a3b22889db9c..b340ad509e3c4 100644 --- a/tests/stdlib/tstrbasics.nim +++ b/tests/stdlib/tstrbasics.nim @@ -5,122 +5,86 @@ discard """ import std/[strbasics, sugar] +template strip2(input: string, args: varargs[untyped]): untyped = + var a = input + when varargsLen(args) > 0: + strip(a, args) + else: + strip(a) + a + proc main() = - when not defined(gcArc): # pending bug #17173 - block: # strip + block: # strip + block: # bug #17173 var a = " vhellov " strip(a) doAssert a == "vhellov" - a = " vhellov " - a.strip(leading = false) - doAssert a == " vhellov" - - a = " vhellov " - a.strip(trailing = false) - doAssert a == "vhellov " - - a.strip() - a.strip(chars = {'v'}) - doAssert a == "hello" - - a = " vhellov " - a.strip() - a.strip(leading = false, chars = {'v'}) - doAssert a == "vhello" - - var c = "blaXbla" - c.strip(chars = {'b', 'a'}) - doAssert c == "laXbl" - c = "blaXbla" - c.strip(chars = {'b', 'a', 'l'}) - doAssert c == "X" - - block: - var a = "xxxxxx" - a.strip(chars={'x'}) - doAssert a.len == 0 - - block: - var a = "x" - a.strip(chars={'x'}) - doAssert a.len == 0 - - block: - var a = "x" - a.strip(chars={'1'}) - doAssert a.len == 1 - - block: - var a = "" - a.strip(chars={'x'}) - doAssert a.len == 0 - - block: - var a = "xxx xxx" - a.strip(chars={'x'}) - doAssert a == " " - - block: - var a = "xxx wind" - a.strip(chars={'x'}) - doAssert a == " wind" - - block: - var a = "xxx iii" - a.strip(chars={'i'}) - doAssert a == "xxx " - - block: - var a = "xxx iii" - doAssert a.dup(strip(chars = {'i'})) == "xxx " - doAssert a.dup(strip(chars = {' '})) == "xxx iii" - doAssert a.dup(strip(chars = {'x'})) == " iii" - doAssert a.dup(strip(chars = {'x', ' '})) == "iii" - doAssert a.dup(strip(chars = {'x', 'i'})) == " " - doAssert a.dup(strip(chars = {'x', 'i', ' '})).len == 0 - - block: - var a = "x i" - doAssert a.dup(strip(chars = {'i'})) == "x " - doAssert a.dup(strip(chars = {' '})) == "x i" - doAssert a.dup(strip(chars = {'x'})) == " i" - doAssert a.dup(strip(chars = {'x', ' '})) == "i" - doAssert a.dup(strip(chars = {'x', 'i'})) == " " - doAssert a.dup(strip(chars = {'x', 'i', ' '})).len == 0 - - block: - var a = "" - doAssert a.dup(strip(chars = {'i'})).len == 0 - doAssert a.dup(strip(chars = {' '})).len == 0 - doAssert a.dup(strip(chars = {'x'})).len == 0 - doAssert a.dup(strip(chars = {'x', ' '})).len == 0 - doAssert a.dup(strip(chars = {'x', 'i'})).len == 0 - doAssert a.dup(strip(chars = {'x', 'i', ' '})).len == 0 - - block: - var a = " " - doAssert a.dup(strip(chars = {'i'})) == " " - doAssert a.dup(strip(chars = {' '})).len == 0 - doAssert a.dup(strip(chars = {'x'})) == " " - doAssert a.dup(strip(chars = {'x', ' '})).len == 0 - doAssert a.dup(strip(chars = {'x', 'i'})) == " " - doAssert a.dup(strip(chars = {'x', 'i', ' '})).len == 0 - - block: # setSlice - var a = "Hello, Nim!" - doassert a.dup(setSlice(7 .. 9)) == "Nim" - doAssert a.dup(setSlice(0 .. 0)) == "H" - doAssert a.dup(setSlice(0 .. 1)) == "He" - doAssert a.dup(setSlice(0 .. 10)) == a - doAssert a.dup(setSlice(1 .. 0)).len == 0 - doAssert a.dup(setSlice(20 .. -1)).len == 0 - - doAssertRaises(AssertionDefect): - discard a.dup(setSlice(-1 .. 1)) - - doAssertRaises(AssertionDefect): - discard a.dup(setSlice(1 .. 11)) + doAssert strip2(" vhellov ") == "vhellov" + doAssert strip2(" vhellov ", leading = false) == " vhellov" + doAssert strip2(" vhellov ", trailing = false) == "vhellov " + doAssert strip2("vhellov", chars = {'v'}) == "hello" + doAssert strip2("vhellov", leading = false, chars = {'v'}) == "vhello" + doAssert strip2("blaXbla", chars = {'b', 'a'}) == "laXbl" + doAssert strip2("blaXbla", chars = {'b', 'a', 'l'}) == "X" + doAssert strip2("xxxxxx", chars={'x'}) == "" + doAssert strip2("x", chars={'x'}) == "" + doAssert strip2("x", chars={'1'}) == "x" + doAssert strip2("", chars={'x'}) == "" + doAssert strip2("xxx xxx", chars={'x'}) == " " + doAssert strip2("xxx wind", chars={'x'}) == " wind" + doAssert strip2("xxx iii", chars={'i'}) == "xxx " + + block: + var a = "xxx iii" + doAssert a.dup(strip(chars = {'i'})) == "xxx " + doAssert a.dup(strip(chars = {' '})) == "xxx iii" + doAssert a.dup(strip(chars = {'x'})) == " iii" + doAssert a.dup(strip(chars = {'x', ' '})) == "iii" + doAssert a.dup(strip(chars = {'x', 'i'})) == " " + doAssert a.dup(strip(chars = {'x', 'i', ' '})).len == 0 + + block: + var a = "x i" + doAssert a.dup(strip(chars = {'i'})) == "x " + doAssert a.dup(strip(chars = {' '})) == "x i" + doAssert a.dup(strip(chars = {'x'})) == " i" + doAssert a.dup(strip(chars = {'x', ' '})) == "i" + doAssert a.dup(strip(chars = {'x', 'i'})) == " " + doAssert a.dup(strip(chars = {'x', 'i', ' '})).len == 0 + + block: + var a = "" + doAssert a.dup(strip(chars = {'i'})).len == 0 + doAssert a.dup(strip(chars = {' '})).len == 0 + doAssert a.dup(strip(chars = {'x'})).len == 0 + doAssert a.dup(strip(chars = {'x', ' '})).len == 0 + doAssert a.dup(strip(chars = {'x', 'i'})).len == 0 + doAssert a.dup(strip(chars = {'x', 'i', ' '})).len == 0 + + block: + var a = " " + doAssert a.dup(strip(chars = {'i'})) == " " + doAssert a.dup(strip(chars = {' '})).len == 0 + doAssert a.dup(strip(chars = {'x'})) == " " + doAssert a.dup(strip(chars = {'x', ' '})).len == 0 + doAssert a.dup(strip(chars = {'x', 'i'})) == " " + doAssert a.dup(strip(chars = {'x', 'i', ' '})).len == 0 + + block: # setSlice + var a = "Hello, Nim!" + doassert a.dup(setSlice(7 .. 9)) == "Nim" + doAssert a.dup(setSlice(0 .. 0)) == "H" + doAssert a.dup(setSlice(0 .. 1)) == "He" + doAssert a.dup(setSlice(0 .. 10)) == a + doAssert a.dup(setSlice(1 .. 0)).len == 0 + doAssert a.dup(setSlice(20 .. -1)).len == 0 + + doAssertRaises(AssertionDefect): + discard a.dup(setSlice(-1 .. 1)) + + doAssertRaises(AssertionDefect): + discard a.dup(setSlice(1 .. 11)) block: # add var a0 = "hi"