aboutsummaryrefslogtreecommitdiff
path: root/v_windows/v/old/cmd/tools/vast/test
diff options
context:
space:
mode:
authorIndrajith K L2022-12-03 17:00:20 +0530
committerIndrajith K L2022-12-03 17:00:20 +0530
commitf5c4671bfbad96bf346bd7e9a21fc4317b4959df (patch)
tree2764fc62da58f2ba8da7ed341643fc359873142f /v_windows/v/old/cmd/tools/vast/test
downloadcli-tools-windows-f5c4671bfbad96bf346bd7e9a21fc4317b4959df.tar.gz
cli-tools-windows-f5c4671bfbad96bf346bd7e9a21fc4317b4959df.tar.bz2
cli-tools-windows-f5c4671bfbad96bf346bd7e9a21fc4317b4959df.zip
Adds most of the toolsHEADmaster
Diffstat (limited to 'v_windows/v/old/cmd/tools/vast/test')
-rw-r--r--v_windows/v/old/cmd/tools/vast/test/.gitignore1
-rw-r--r--v_windows/v/old/cmd/tools/vast/test/demo.v121
2 files changed, 122 insertions, 0 deletions
diff --git a/v_windows/v/old/cmd/tools/vast/test/.gitignore b/v_windows/v/old/cmd/tools/vast/test/.gitignore
new file mode 100644
index 0000000..857cade
--- /dev/null
+++ b/v_windows/v/old/cmd/tools/vast/test/.gitignore
@@ -0,0 +1 @@
+demo.json
diff --git a/v_windows/v/old/cmd/tools/vast/test/demo.v b/v_windows/v/old/cmd/tools/vast/test/demo.v
new file mode 100644
index 0000000..a2176b1
--- /dev/null
+++ b/v_windows/v/old/cmd/tools/vast/test/demo.v
@@ -0,0 +1,121 @@
+// usage test: v ast path_to_v/cmd/tools/vast/test/demo.v
+// will generate demo.json
+
+// comment for module
+module main
+
+// import module
+import os
+import math
+import time { Time, now }
+
+// const decl
+const (
+ a = 1
+ b = 3
+ c = 'c'
+)
+
+// struct decl
+struct Point {
+ x int
+mut:
+ y int
+pub:
+ z int
+pub mut:
+ name string
+}
+
+// method of Point
+pub fn (p Point) get_x() int {
+ return p.x
+}
+
+// embed struct
+struct MyPoint {
+ Point
+ title string
+}
+
+// enum type
+enum Color {
+ red
+ green
+ blue
+}
+
+// type alias
+type Myint = int
+
+// sum type
+type MySumType = bool | int | string
+
+// function type
+type Myfn = fn (int) int
+
+// interface type
+interface Myinterfacer {
+ add(int, int) int
+ sub(int, int) int
+}
+
+// main funciton
+fn main() {
+ add(1, 3)
+ println(add(1, 2))
+ println('ok') // comment println
+ arr := [1, 3, 5, 7]
+ for a in arr {
+ println(a)
+ add(1, 3)
+ }
+ color := Color.red
+ println(color)
+ println(os.args)
+ m := math.max(1, 3)
+ println(m)
+ println(now())
+ t := Time{}
+ println(t)
+ p := Point{
+ x: 1
+ y: 2
+ z: 3
+ }
+ println(p)
+ my_point := MyPoint{
+ // x: 1
+ // y: 3
+ // z: 5
+ }
+ println(my_point.get_x())
+}
+
+// normal function
+fn add(x int, y int) int {
+ return x + y
+}
+
+// function with defer stmt
+fn defer_fn() {
+ mut x := 1
+ println('start fn')
+ defer {
+ println('in defer block')
+ println(x)
+ }
+ println('end fn')
+}
+
+// generic function
+fn g_fn<T>(p T) T {
+ return p
+}
+
+// generic struct
+struct GenericStruct<T> {
+ point Point
+mut:
+ model T
+}