summary refs log tree commit diff stats
path: root/tests/misc/tnoop.nim
Commit message (Expand)AuthorAgeFilesLines
* close #17636 (#17643)flywind2021-04-061-2/+1
* honor --declaredLocs in more places, including type mismatch errors; also sho...Timothee Cour2020-10-271-1/+1
* correct tnoop test caseAraq2018-10-251-2/+3
* fixes #8671; show helpful msg (lookup symbol, eg iterator) on 'attempting to ...Timothee Cour2018-10-141-3/+4
* s/procedure/routine/ in tests.Dominik Picheta2015-06-051-1/+1
* Fixes #2584Dominik Picheta2015-06-041-1/+1
* fixes --gc:none regression; made some tests greenAraq2015-03-101-4/+3
* Merge pull request #1075 from flaviut/inlinedocsAndreas Rumpf2014-04-091-0/+12
an class='oid'>f8af7ed6b ^
3be07d842 ^



f8af7ed6b ^











f8af7ed6b ^
e80465dac ^

f8af7ed6b ^


ae82406c8 ^
f8af7ed6b ^

e80465dac ^
f8af7ed6b ^

































b3ac785f9 ^




47e4f9698 ^



e80465dac ^
d8fde9dab ^
47e4f9698 ^




ae82406c8 ^
9fdb13168 ^





212293197 ^




ae82406c8 ^
212293197 ^






















5b57abe35 ^
















0b0baece8 ^










dbbe311e1 ^









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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
           
               
            


                          
      

    



               



                                                  











                                          
 

                               


                             
                                                       

                     
                   

































                                   




                                     



          
           
                                




                                                
                                           





                      




           
                                  






















                                            
















                                        










                                        









                                             
discard """
  output: '''24
(bar: "bar")
1244
6
abcdefghijklmnopqrstuvwxyz
145 23
3
2'''
"""

import strutils

const fac4 = (var x = 1; for i in 1..4: x *= i; x)

echo fac4

when true:
  proc test(foo: proc (x, y: int): bool) =
    echo foo(5, 5)


  type Foo = object
    bar: string

  proc newfoo(): Foo =
    result.bar = "bar"

  echo($newfoo())


  proc retInt(x, y: int): int =
    if (var yy = 0; yy != 0):
      echo yy
    else:
      echo(try: parseInt("1244") except ValueError: -1)
    result = case x
             of 23: 3
             of 64:
                    case y
                    of 1: 2
                    of 2: 3
                    of 3: 6
                    else: 8
             else: 1

  echo retInt(64, 3)

  proc buildString(): string =
    result = ""
    for x in 'a'..'z':
      result.add(x)

  echo buildString()

#test(
#  proc (x, y: int): bool =
#  if x == 5: return true
#  if x == 2: return false
#  if y == 78: return true
#)

proc q(): int {.discardable.} = 145
proc p(): int =
  q()

proc p2(a: int): int =
  # result enforces a void context:
  if a == 2:
    result = 23
  q()

echo p(), " ", p2(2)

proc semiProblem() =
  if false: echo "aye"; echo "indeed"

semiProblem()


# bug #844

import json
proc parseResponse(): JsonNode =
  result = % { "key1": % { "key2": % "value" } }
  for key, val in result["key1"]:
    var excMsg = key & "("
    if (var n=result["key2"]; n != nil):
      excMsg &= n.str
    raise newException(SystemError, excMsg)



#bug #992
var se = @[1,2]
let b = (se[1] = 1; 1)


# bug #1161

type
  PFooBase = ref object of RootRef
    field: int

  PFoo[T] = ref object of PFooBase
    field2: T

var testIf =
  if true:
    2
  else:
    3

var testCase =
  case 8
  of 8: 9
  else: 10

var testTry =
  try:
    PFoo[string](field: 3, field2: "asfasf")
  except:
    PFooBase(field: 5)

echo(testTry.field)

# bug #6166

proc quo(op: proc (x: int): bool): int =
  result =
     if op(3):
        2
     else:
        0

echo(
  if true:
     quo do (a: int) -> bool:
        a mod 2 != 0
  else:
     quo do (a: int) -> bool:
        a mod 3 != 0
)

# bug #6980

proc fooBool: bool {.discardable.} =
  true

if true:
  fooBool()
else:
  raise newException(ValueError, "argh")

# bug #5374

proc test1(): int64 {.discardable.} = discard
proc test2(): int {.discardable.} = discard

if true:
  test1()
else:
  test2()