summary refs log tree commit diff stats
path: root/tests/template/tmore_regressions.nim
blob: 8b4b5fa4c75e56b9d332758d0ea5e081bb7893b2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
discard """
output: '''0

0.0'''
"""

# bug #11494
import macros

macro staticForEach(arr: untyped, body: untyped): untyped =
    result = newNimNode(nnkStmtList)

    arr.expectKind(nnkBracket)
    for n in arr:
        let b = copyNimTree(body)
        result.add quote do:
            block:
                type it {.inject.} = `n`
                `b`

template forEveryMatchingEntity*() =
    staticForEach([int, string, float]):
        var a: it
        echo a

forEveryMatchingEntity()


# bug #11483
proc main =
  template first(body) =
    template second: var int =
      var o: int
      var i  = addr(o)
      i[]

    body

  first:
    second = 5
    second = 6

main()
com> 2017-11-26 22:52:39 +0000 committer Dominik Picheta <dominikpicheta@gmail.com> 2017-11-26 22:52:39 +0000 Add an attempted reproduction for #5531.' href='/ahoang/Nim/commit/tests/async/tasyncfile.nim?h=devel&id=4d931c62763fd68e3f6e874f977402f3ae5d144b'>4d931c627 ^
19164929e ^






4d931c627 ^
0f3025e32 ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
           



               
                        




                                   

                                      
 


                                         
                               

                           
                       



                                   
 




                                      
                   



                                   
 

                                  
 






                                     
                          


                                   
                         

                






                                                       
 
              
discard """
  output: '''13
hello humans!
13
'''
  file: "tasyncfile.nim"
  exitcode: 0
"""
import asyncfile, asyncdispatch, os

proc main() {.async.} =
  let fn = getTempDir() / "foobar.txt"
  removeFile(fn)

  # Simple write/read test.
  block:
    var file = openAsync(fn, fmReadWrite)
    await file.write("testing")
    file.setFilePos(0)
    await file.write("foo")
    file.setFileSize(4)
    file.setFilePos(0)
    let data = await file.readAll()
    doAssert data == "foot"
    file.close()

  # Append test
  block:
    var file = openAsync(fn, fmAppend)
    await file.write("\ntest2")
    let errorTest = file.readAll()
    yield errorTest
    doAssert errorTest.failed
    file.close()
    file = openAsync(fn, fmRead)
    let data = await file.readAll()

    doAssert data == "foot\ntest2"
    file.close()

  # Issue #5531
  block:
    removeFile(fn)
    var file = openAsync(fn, fmWrite)
    await file.write("test2")
    file.close()
    file = openAsync(fn, fmWrite)
    await file.write("t3")
    file.close()
    file = openAsync(fn, fmRead)
    let data = await file.readAll()
    doAssert data == "t3"
    file.close()

  # Issue #7347
  block:
    let appDir = getAppDir()
    var file = openAsync(appDir & DirSep & "hello.txt")
    echo file.getFileSize()
    echo await file.readAll()
    echo file.getFilePos()

waitFor main()