fixes merge conflict

This commit is contained in:
Araq 2018-08-23 11:30:55 +02:00
commit 30597e643f
40 changed files with 1844 additions and 1695 deletions

View file

@ -0,0 +1,11 @@
discard """
cmd: "nim $target -d:release $options $file"
output: '''
assertion occured!!!!!! false
'''
"""
onFailedAssert(msg):
echo("assertion occured!!!!!! ", msg)
doAssert(1 == 2)

View file

@ -11,3 +11,15 @@ type Monoid = concept x, y
proc z(x: typedesc[int]): int = 0
echo(int is Monoid)
# https://github.com/nim-lang/Nim/issues/8126
type AdditiveMonoid* = concept x, y, type T
x + y is T
# some redundant checks to test an alternative approaches:
type TT = type(x)
x + y is type(x)
x + y is TT
doAssert(1 is AdditiveMonoid)

View file

@ -0,0 +1,10 @@
type
Ty* {.deprecated.} = uint32
Ty1* {.deprecated: "hello".} = uint32
var aVar* {.deprecated.}: char
proc aProc*() {.deprecated.} = discard
proc aProc1*() {.deprecated: "hello".} = discard
{.deprecated: "goodbye".}

View file

@ -0,0 +1,23 @@
discard """
nimout: '''tmodule1.nim(11, 8) Warning: goodbye; importme is deprecated [Deprecated]
tmodule1.nim(14, 10) Warning: Ty is deprecated [Deprecated]
tmodule1.nim(17, 10) Warning: hello; Ty1 is deprecated [Deprecated]
tmodule1.nim(20, 8) Warning: aVar is deprecated [Deprecated]
tmodule1.nim(22, 3) Warning: aProc is deprecated [Deprecated]
tmodule1.nim(23, 3) Warning: hello; aProc1 is deprecated [Deprecated]
'''
"""
import importme
block:
var z: Ty
z = 0
block:
var z: Ty1
z = 0
block:
echo aVar
block:
aProc()
aProc1()

View file

@ -0,0 +1,7 @@
discard """
line: 7
errormsg: "annotation to deprecated not supported here"
"""
var foo* {.deprecated.} = 42
var foo1* {.deprecated: "no".} = 42

8
tests/errmsgs/t8339.nim Normal file
View file

@ -0,0 +1,8 @@
discard """
line: 8
errormsg: "type mismatch: got <seq[int]> but expected 'seq[float]'"
"""
import sequtils
var x: seq[float] = @[1].mapIt(it)

View file

@ -1,43 +0,0 @@
discard """
action: run
"""
import times
# $ date --date='@2147483647'
# Tue 19 Jan 03:14:07 GMT 2038
block yeardayTest:
doAssert fromUnix(2147483647).utc.yearday == 18
block localTime:
var local = now()
let utc = local.utc
doAssert local.toTime == utc.toTime
let a = fromUnix(1_000_000_000)
let b = fromUnix(1_500_000_000)
doAssert b - a == initDuration(seconds = 500_000_000)
# Because we can't change the timezone JS uses, we define a simple static timezone for testing.
proc zonedTimeFromTime(time: Time): ZonedTime =
result.utcOffset = -7200
result.isDst = false
result.time = time
proc zonedTimeFromAdjTime(adjTime: Time): ZonedTIme =
result.utcOffset = -7200
result.isDst = false
result.time = adjTime + initDuration(seconds = -7200)
let utcPlus2 = newTimezone("", zonedTimeFromTime, zonedTimeFromAdjTime)
block timezoneTests:
let dt = initDateTime(01, mJan, 2017, 12, 00, 00, utcPlus2)
doAssert $dt == "2017-01-01T12:00:00+02:00"
doAssert $dt.utc == "2017-01-01T10:00:00Z"
doAssert $dt.utc.inZone(utcPlus2) == $dt
doAssert $initDateTime(01, mJan, 1911, 12, 00, 00, utc()) == "1911-01-01T12:00:00Z"
doAssert $initDateTime(01, mJan, 0023, 12, 00, 00, utc()) == "0023-01-01T12:00:00Z"

29
tests/magics/t8693.nim Normal file
View file

@ -0,0 +1,29 @@
discard """
output: '''true
false
true
false
false
true
true
false
true
true
'''
"""
type Foo = int | float
proc bar(t1, t2: typedesc): bool =
echo (t1 is t2)
(t2 is t1)
proc bar[T](x: T, t2: typedesc): bool =
echo (T is t2)
(t2 is T)
echo bar(int, Foo)
echo bar(4, Foo)
echo bar(any, int)
echo bar(int, any)
echo bar(Foo, Foo)

View file

@ -9,6 +9,7 @@ doAssertRaises(DivByZeroError): discard 1 mod 0
doAssertRaises(DivByZeroError): discard 1 div 0
doAssertRaises(OverflowError): discard low(int8) div -1'i8
doAssertRaises(OverflowError): discard -low(int64)
doAssertRaises(OverflowError): discard low(int64) - 1'i64
doAssertRaises(OverflowError): discard high(int64) + 1'i64
@ -21,3 +22,6 @@ doAssertRaises(OverflowError): discard low(int64) * -1
doAssertRaises(OverflowError): discard high(int8) * 2
doAssertRaises(OverflowError): discard high(int64) * 2
doAssert abs(-1) == 1
doAssert 2 div 2 == 1
doAssert 2 * 3 == 6

1
tests/modules/t8665.nim Normal file
View file

@ -0,0 +1 @@
import treorder

View file

@ -0,0 +1,11 @@
discard """
action: run
"""
import .. / modules / [definitions as foo]
import std / times as bar
import definitions as baz
discard foo.v
discard bar.now
discard baz.v

View file

@ -40,3 +40,7 @@ static:
assert y isnot tuple
assert z isnot seq
# XXX: These cases don't work properly at the moment:
# assert type[int] isnot int
# assert type(int) isnot int

10
tests/proc/t8357.nim Normal file
View file

@ -0,0 +1,10 @@
discard """
output: "Hello"
"""
type
T = ref int
let r = new(string)
r[] = "Hello"
echo r[]

11
tests/proc/t8683.nim Normal file
View file

@ -0,0 +1,11 @@
discard """
output: "1"
"""
proc foo[T](bar: proc (x, y: T): int = system.cmp, baz: int) =
echo "1"
proc foo[T](bar: proc (x, y: T): int = system.cmp) =
echo "2"
foo[int](baz = 5)

36
tests/stdlib/tropes.nim Normal file
View file

@ -0,0 +1,36 @@
discard """
file: "tropes.nim"
output: '''0
3
123
3
6
123
123456
2
3'''
"""
import ropes
var
r1 = rope("")
r2 = rope("123")
echo r1.len
echo r2.len
echo r1
echo r2
r1.add("123")
r2.add("456")
echo r1.len
echo r2.len
echo r1
echo r2
echo r1[1]
echo r2[2]

View file

@ -1,12 +1,20 @@
# test the new time module
discard """
file: "ttimes.nim"
target: "c js"
output: '''[Suite] ttimes
'''
"""
import
times, os, strutils, unittest
import times, strutils, unittest
when not defined(js):
import os
# Normally testament configures unittest with environment variables,
# but that doesn't work for the JS target. So instead we must set the correct
# settings here.
addOutputFormatter(
newConsoleOutputFormatter(PRINT_FAILURES, colorOutput = false))
proc staticTz(hours, minutes, seconds: int = 0): Timezone {.noSideEffect.} =
let offset = hours * 3600 + minutes * 60 + seconds
@ -23,99 +31,12 @@ proc staticTz(hours, minutes, seconds: int = 0): Timezone {.noSideEffect.} =
newTimezone("", zonedTimeFromTime, zonedTImeFromAdjTime)
# $ date --date='@2147483647'
# Tue 19 Jan 03:14:07 GMT 2038
proc checkFormat(t: DateTime, format, expected: string) =
let actual = t.format(format)
if actual != expected:
echo "Formatting failure!"
echo "expected: ", expected
echo "actual : ", actual
doAssert false
let t2 = fromUnix(160070789).utc() # Mon 27 Jan 16:06:29 GMT 1975
t2.checkFormat("d dd ddd dddd h hh H HH m mm M MM MMM MMMM s" &
" ss t tt y yy yyy yyyy yyyyy z zz zzz",
"27 27 Mon Monday 4 04 16 16 6 06 1 01 Jan January 29 29 P PM 5 75 975 1975 01975 Z Z Z")
var t4 = fromUnix(876124714).utc # Mon 6 Oct 08:58:34 BST 1997
t4.checkFormat("M MM MMM MMMM", "10 10 Oct October")
# Interval tests
(t4 - initTimeInterval(years = 2)).checkFormat("yyyy", "1995")
(t4 - initTimeInterval(years = 7, minutes = 34, seconds = 24)).checkFormat("yyyy mm ss", "1990 24 10")
# checking dayOfWeek matches known days
doAssert getDayOfWeek(01, mJan, 0000) == dSat
doAssert getDayOfWeek(01, mJan, -0023) == dSat
doAssert getDayOfWeek(21, mSep, 1900) == dFri
doAssert getDayOfWeek(01, mJan, 1970) == dThu
doAssert getDayOfWeek(21, mSep, 1970) == dMon
doAssert getDayOfWeek(01, mJan, 2000) == dSat
doAssert getDayOfWeek(01, mJan, 2021) == dFri
# toUnix tests with GM timezone
let t4L = fromUnix(876124714).utc
doAssert toUnix(toTime(t4L)) == 876124714
doAssert toUnix(toTime(t4L)) + t4L.utcOffset == toUnix(toTime(t4))
# adding intervals
var
a1L = toUnix(toTime(t4L + initTimeInterval(hours = 1))) + t4L.utcOffset
a1G = toUnix(toTime(t4)) + 60 * 60
doAssert a1L == a1G
# subtracting intervals
a1L = toUnix(toTime(t4L - initTimeInterval(hours = 1))) + t4L.utcOffset
a1G = toUnix(toTime(t4)) - (60 * 60)
doAssert a1L == a1G
# Comparison between Time objects should be detected by compiler
# as 'noSideEffect'.
proc cmpTimeNoSideEffect(t1: Time, t2: Time): bool {.noSideEffect.} =
result = t1 == t2
doAssert cmpTimeNoSideEffect(0.fromUnix, 0.fromUnix)
# Additionally `==` generic for seq[T] has explicit 'noSideEffect' pragma
# so we can check above condition by comparing seq[Time] sequences
let seqA: seq[Time] = @[]
let seqB: seq[Time] = @[]
doAssert seqA == seqB
for tz in [
(staticTz(seconds = 0), "+0", "+00", "+00:00"), # UTC
(staticTz(seconds = -3600), "+1", "+01", "+01:00"), # CET
(staticTz(seconds = -39600), "+11", "+11", "+11:00"), # two digits
(staticTz(seconds = -1800), "+0", "+00", "+00:30"), # half an hour
(staticTz(seconds = 7200), "-2", "-02", "-02:00"), # positive
(staticTz(seconds = 38700), "-10", "-10", "-10:45")]: # positive with three quaters hour
let dt = initDateTime(1, mJan, 2000, 00, 00, 00, tz[0])
doAssert dt.format("z") == tz[1]
doAssert dt.format("zz") == tz[2]
doAssert dt.format("zzz") == tz[3]
block countLeapYears:
# 1920, 2004 and 2020 are leap years, and should be counted starting at the following year
doAssert countLeapYears(1920) + 1 == countLeapYears(1921)
doAssert countLeapYears(2004) + 1 == countLeapYears(2005)
doAssert countLeapYears(2020) + 1 == countLeapYears(2021)
block timezoneConversion:
var l = now()
let u = l.utc
l = u.local
doAssert l.timezone == local()
doAssert u.timezone == utc()
template parseTest(s, f, sExpected: string, ydExpected: int) =
let
parsed = s.parse(f, utc())
parsedStr = $parsed
if parsedStr != sExpected:
echo "GOT ", parsedStr, " EXPECTED ", sExpected, " FORMAT ", f
check parsedStr == sExpected
check(parsed.yearday == ydExpected)
check parsed.yearday == ydExpected
template parseTestExcp(s, f: string) =
expect ValueError:
@ -192,7 +113,7 @@ suite "ttimes":
# Generate tests for multiple timezone files where available
# Set the TZ env var for each test
when defined(Linux) or defined(macosx):
when defined(linux) or defined(macosx):
const tz_dir = "/usr/share/zoneinfo"
const f = "yyyy-MM-dd HH:mm zzz"
@ -333,7 +254,19 @@ suite "ttimes":
check isLeapYear(2000)
check (not isLeapYear(1900))
test "subtract months":
test "TimeInterval":
let t = fromUnix(876124714).utc # Mon 6 Oct 08:58:34 BST 1997
# Interval tests
let t2 = t - 2.years
check t2.year == 1995
let t3 = (t - 7.years - 34.minutes - 24.seconds)
check t3.year == 1990
check t3.minute == 24
check t3.second == 10
check (t + 1.hours).toTime.toUnix == t.toTime.toUnix + 60 * 60
check (t - 1.hours).toTime.toUnix == t.toTime.toUnix - 60 * 60
test "TimeInterval - months":
var dt = initDateTime(1, mFeb, 2017, 00, 00, 00, utc())
check $(dt - initTimeInterval(months = 1)) == "2017-01-01T00:00:00Z"
dt = initDateTime(15, mMar, 2017, 00, 00, 00, utc())
@ -404,14 +337,17 @@ suite "ttimes":
let day = 24.hours
let tomorrow = now + day
check tomorrow - now == initDuration(days = 1)
test "fromWinTime/toWinTime":
check 0.fromUnix.toWinTime.fromWinTime.toUnix == 0
check (-1).fromWinTime.nanosecond == convert(Seconds, Nanoseconds, 1) - 100
check -1.fromWinTime.toWinTime == -1
# One nanosecond is discarded due to differences in time resolution
check initTime(0, 101).toWinTime.fromWinTime.nanosecond == 100
check initTime(0, 101).toWinTime.fromWinTime.nanosecond == 100
# Disabled for JS because it fails due to precision errors
# (The JS target uses float64 for int64).
when not defined(js):
test "fromWinTime/toWinTime":
check 0.fromUnix.toWinTime.fromWinTime.toUnix == 0
check (-1).fromWinTime.nanosecond == convert(Seconds, Nanoseconds, 1) - 100
check (-1).fromWinTime.toWinTime == -1
# One nanosecond is discarded due to differences in time resolution
check initTime(0, 101).toWinTime.fromWinTime.nanosecond == 100
check initTime(0, 101).toWinTime.fromWinTime.nanosecond == 100
test "issue 7620":
let layout = "M/d/yyyy' 'h:mm:ss' 'tt' 'z"
@ -477,6 +413,18 @@ suite "ttimes":
expect ValueError:
discard initTimeFormat("foo'")
for tz in [
(staticTz(seconds = 0), "+0", "+00", "+00:00"), # UTC
(staticTz(seconds = -3600), "+1", "+01", "+01:00"), # CET
(staticTz(seconds = -39600), "+11", "+11", "+11:00"), # two digits
(staticTz(seconds = -1800), "+0", "+00", "+00:30"), # half an hour
(staticTz(seconds = 7200), "-2", "-02", "-02:00"), # positive
(staticTz(seconds = 38700), "-10", "-10", "-10:45")]: # positive with three quaters hour
let dt = initDateTime(1, mJan, 2000, 00, 00, 00, tz[0])
doAssert dt.format("z") == tz[1]
doAssert dt.format("zz") == tz[2]
doAssert dt.format("zzz") == tz[3]
test "parse":
check $parse("20180101", "yyyyMMdd", utc()) == "2018-01-01T00:00:00Z"
parseTestExcp("+120180101", "yyyyMMdd")
@ -497,3 +445,26 @@ suite "ttimes":
discard parse("'", "''")
parseTestExcp("2000 A", "yyyy g")
test "countLeapYears":
# 1920, 2004 and 2020 are leap years, and should be counted starting at the following year
check countLeapYears(1920) + 1 == countLeapYears(1921)
check countLeapYears(2004) + 1 == countLeapYears(2005)
check countLeapYears(2020) + 1 == countLeapYears(2021)
test "timezoneConversion":
var l = now()
let u = l.utc
l = u.local
check l.timezone == local()
check u.timezone == utc()
test "getDayOfWeek":
check getDayOfWeek(01, mJan, 0000) == dSat
check getDayOfWeek(01, mJan, -0023) == dSat
check getDayOfWeek(21, mSep, 1900) == dFri
check getDayOfWeek(01, mJan, 1970) == dThu
check getDayOfWeek(21, mSep, 1970) == dMon
check getDayOfWeek(01, mJan, 2000) == dSat
check getDayOfWeek(01, mJan, 2021) == dFri

View file

@ -22,8 +22,8 @@ proc generateTestResultPanelPartial(outfile: File, testResultRow: JsonNode) =
target = testResultRow["target"].str.htmlQuote()
action = testResultRow["action"].str.htmlQuote()
result = htmlQuote testResultRow["result"].str
expected = testResultRow["expected"].str
gotten = testResultRow["given"].str
expected = testResultRow["expected"].getStr
gotten = testResultRow["given"].getStr
timestamp = "unknown"
var
panelCtxClass, textCtxClass, bgCtxClass: string