#!/usr/bin/env ascript
tester(test:expr):map:dynamic_scope = printf("%s .. %s\n", test, eval(test)):nomap

lambda {
	nLines = 0
	open("test-file.az").readlines():chop {|line|
		println(line)
		nLines += 1
	}
	printf("<nLines = %d>\n", nLines)
}()
lambda {
	tester(`[path.glob("test-*.az")])
	tester(`path.glob("test-*.az"):list {|filename|
		filename.upper()
	})
	tester(`path.glob("test-*.az"):xlist {|filename|
		if (string.find(filename, "op")) { filename }
	})
}()
lambda {
	import(re)
	tester(`path.dir("."):xlist {|filename|
		if (m = filename.match(r"test-([^\.]*)")) { m.group(1) }
	})
}()
lambda {
	tester(`path.match("foo*", ["foo", "FOObar", "bar"]))
	tester(`path.match("foo*", ["foo", "FOObar", "bar"]):icase)
}()
lambda {
	println(path.dir() {|filename, i| "%3d %s" % [i, filename]})
}()
lambda {
	stats = path.glob("test-*.az"):list:stat
	println("sort by name")
	for (stat in stats.sort(&{$s1.basename <=> $s2.basename})) {
		printf("%-32s %s\n", stat.basename, stat.mtime.format("%Y-%m-%d %H:%M:%S"))
	}
	println("sort by creation time")
	for (stat in stats.sort(&{$s1.mtime <=> $s2.mtime})) {
		printf("%-32s %s\n", stat.basename, stat.mtime.format("%Y-%m-%d %H:%M:%S"))
	}
}()
