diff options
author | Dominik Picheta <dominikpicheta@gmail.com> | 2018-05-04 15:44:36 +0100 |
---|---|---|
committer | Dominik Picheta <dominikpicheta@gmail.com> | 2018-06-17 00:12:51 +0100 |
commit | 9e8623785577aff8ecffaea27f8cdc0d98c1edb1 (patch) | |
tree | 9b90729fe1aaa0fc2871520d4211c34171182e56 /tests/niminaction/Chapter1 | |
parent | 8081a9b3d0e31d144d0aa7c4d954c905fa564a7a (diff) | |
download | Nim-9e8623785577aff8ecffaea27f8cdc0d98c1edb1.tar.gz |
Adds smaller code samples from Chapters 1-3 to the tester.
Diffstat (limited to 'tests/niminaction/Chapter1')
-rw-r--r-- | tests/niminaction/Chapter1/various1.nim | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/niminaction/Chapter1/various1.nim b/tests/niminaction/Chapter1/various1.nim new file mode 100644 index 000000000..688180fd2 --- /dev/null +++ b/tests/niminaction/Chapter1/various1.nim @@ -0,0 +1,45 @@ +discard """ + exitCode: 0 + outputsub: "Woof!" +""" + +import strutils +echo("hello".to_upper()) +echo("world".toUpper()) + +type + Dog = object #<1> + age: int #<2> + +let dog = Dog(age: 3) #<3> + +proc showNumber(num: int | float) = + echo(num) + +showNumber(3.14) +showNumber(42) + +for i in 0 .. <10: + echo(i) + +block: # Block added due to clash. + type + Dog = object + + proc bark(self: Dog) = #<1> + echo("Woof!") + + let dog = Dog() + dog.bark() #<2> + +import sequtils, future, strutils +let list = @["Dominik Picheta", "Andreas Rumpf", "Desmond Hume"] +list.map( + (x: string) -> (string, string) => (x.split[0], x.split[1]) +).echo + +import strutils +let list1 = @["Dominik Picheta", "Andreas Rumpf", "Desmond Hume"] +for name in list1: + echo((name.split[0], name.split[1])) + |