Update.
This commit is contained in:
Vendored
+34
@@ -0,0 +1,34 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
import "fswatch" for FileWatcher, FsEvent
|
||||
import "timer" for Timer
|
||||
import "io" for File, FileFlags
|
||||
|
||||
var testFile = "/tmp/fswatch_test_%(Num.fromString("%(System.clock)".split(".")[1])).txt"
|
||||
|
||||
var f = File.openWithFlags(testFile, FileFlags.writeOnly | FileFlags.create | FileFlags.truncate)
|
||||
f.writeBytes("initial", 0)
|
||||
f.close()
|
||||
|
||||
var watcher = FileWatcher.new(testFile)
|
||||
var received = []
|
||||
|
||||
watcher.start { |event|
|
||||
received.add(event)
|
||||
}
|
||||
|
||||
System.print(watcher.isActive) // expect: true
|
||||
|
||||
Timer.immediate {
|
||||
var f2 = File.openWithFlags(testFile, FileFlags.writeOnly | FileFlags.truncate)
|
||||
f2.writeBytes("modified", 0)
|
||||
f2.close()
|
||||
}
|
||||
|
||||
Timer.sleep(100)
|
||||
|
||||
System.print(received.count > 0) // expect: true
|
||||
System.print(received[0] is FsEvent) // expect: true
|
||||
|
||||
watcher.stop()
|
||||
System.print(watcher.isActive) // expect: false
|
||||
Vendored
+17
@@ -0,0 +1,17 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
import "io" for File
|
||||
|
||||
var srcFile = "/tmp/test_copy_src.txt"
|
||||
var dstFile = "/tmp/test_copy_dst.txt"
|
||||
var content = "Copy me!"
|
||||
|
||||
File.write(srcFile, content)
|
||||
|
||||
File.copy(srcFile, dstFile)
|
||||
|
||||
System.print(File.exists(dstFile)) // expect: true
|
||||
System.print(File.read(dstFile) == content) // expect: true
|
||||
|
||||
File.delete(srcFile)
|
||||
File.delete(dstFile)
|
||||
Vendored
+17
@@ -0,0 +1,17 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
import "io" for File
|
||||
|
||||
var srcFile = "/tmp/test_move_src.txt"
|
||||
var dstFile = "/tmp/test_move_dst.txt"
|
||||
var content = "Move me!"
|
||||
|
||||
File.write(srcFile, content)
|
||||
|
||||
File.move(srcFile, dstFile)
|
||||
|
||||
System.print(File.exists(srcFile)) // expect: false
|
||||
System.print(File.exists(dstFile)) // expect: true
|
||||
System.print(File.read(dstFile) == content) // expect: true
|
||||
|
||||
File.delete(dstFile)
|
||||
Vendored
+13
@@ -0,0 +1,13 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
import "io" for File
|
||||
|
||||
var testFile = "/tmp/test_write_static.txt"
|
||||
var content = "Hello, World!"
|
||||
|
||||
File.write(testFile, content)
|
||||
|
||||
var read = File.read(testFile)
|
||||
System.print(read == content) // expect: true
|
||||
|
||||
File.delete(testFile)
|
||||
Vendored
+13
@@ -0,0 +1,13 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
import "io" for Stdin
|
||||
|
||||
var size = Stdin.windowSize
|
||||
|
||||
System.print(size == null || size is List) // expect: true
|
||||
|
||||
if (size != null) {
|
||||
System.print(size.count == 2)
|
||||
System.print(size[0] > 0)
|
||||
System.print(size[1] > 0)
|
||||
}
|
||||
Vendored
+12
@@ -0,0 +1,12 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
import "pathlib" for Path
|
||||
|
||||
var testFile = Path.new("/tmp/test_pathlib_size.txt")
|
||||
var content = "12345678"
|
||||
testFile.writeText(content)
|
||||
|
||||
var size = testFile.size()
|
||||
System.print(size) // expect: 8
|
||||
|
||||
testFile.unlink()
|
||||
Vendored
+19
@@ -0,0 +1,19 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
import "pathlib" for Path
|
||||
|
||||
var testFile = Path.new("/tmp/test_pathlib_stat_times.txt")
|
||||
testFile.writeText("test content")
|
||||
|
||||
var mtime = testFile.mtime()
|
||||
var atime = testFile.atime()
|
||||
var ctime = testFile.ctime()
|
||||
|
||||
System.print(mtime is Num) // expect: true
|
||||
System.print(atime is Num) // expect: true
|
||||
System.print(ctime is Num) // expect: true
|
||||
System.print(mtime > 0) // expect: true
|
||||
System.print(atime > 0) // expect: true
|
||||
System.print(ctime > 0) // expect: true
|
||||
|
||||
testFile.unlink()
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
import "sysinfo" for SysInfo
|
||||
|
||||
var count = SysInfo.cpuCount
|
||||
System.print(count is Num) // expect: true
|
||||
System.print(count > 0) // expect: true
|
||||
Vendored
+19
@@ -0,0 +1,19 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
import "sysinfo" for SysInfo
|
||||
|
||||
var cpus = SysInfo.cpuInfo
|
||||
System.print(cpus is List) // expect: true
|
||||
System.print(cpus.count > 0) // expect: true
|
||||
|
||||
var cpu = cpus[0]
|
||||
System.print(cpu is Map) // expect: true
|
||||
System.print(cpu.containsKey("model")) // expect: true
|
||||
System.print(cpu.containsKey("speed")) // expect: true
|
||||
System.print(cpu.containsKey("times")) // expect: true
|
||||
|
||||
var times = cpu["times"]
|
||||
System.print(times is Map) // expect: true
|
||||
System.print(times.containsKey("user")) // expect: true
|
||||
System.print(times.containsKey("sys")) // expect: true
|
||||
System.print(times.containsKey("idle")) // expect: true
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
import "sysinfo" for SysInfo
|
||||
|
||||
var hostname = SysInfo.hostname
|
||||
System.print(hostname is String) // expect: true
|
||||
System.print(hostname.count > 0) // expect: true
|
||||
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
import "sysinfo" for SysInfo
|
||||
|
||||
var t1 = SysInfo.hrtime
|
||||
var t2 = SysInfo.hrtime
|
||||
System.print(t1 is Num) // expect: true
|
||||
System.print(t2 is Num) // expect: true
|
||||
System.print(t2 >= t1) // expect: true
|
||||
Vendored
+10
@@ -0,0 +1,10 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
import "sysinfo" for SysInfo
|
||||
|
||||
var load = SysInfo.loadAverage
|
||||
System.print(load is List) // expect: true
|
||||
System.print(load.count) // expect: 3
|
||||
System.print(load[0] is Num) // expect: true
|
||||
System.print(load[1] is Num) // expect: true
|
||||
System.print(load[2] is Num) // expect: true
|
||||
Vendored
+16
@@ -0,0 +1,16 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
import "sysinfo" for SysInfo
|
||||
|
||||
var total = SysInfo.totalMemory
|
||||
var free = SysInfo.freeMemory
|
||||
var resident = SysInfo.residentMemory
|
||||
|
||||
System.print(total is Num) // expect: true
|
||||
System.print(free is Num) // expect: true
|
||||
System.print(resident is Num) // expect: true
|
||||
|
||||
System.print(total > 0) // expect: true
|
||||
System.print(free > 0) // expect: true
|
||||
System.print(resident > 0) // expect: true
|
||||
System.print(total >= free) // expect: true
|
||||
Vendored
+23
@@ -0,0 +1,23 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
import "sysinfo" for SysInfo
|
||||
|
||||
var interfaces = SysInfo.networkInterfaces
|
||||
System.print(interfaces is Map) // expect: true
|
||||
System.print(interfaces.count > 0) // expect: true
|
||||
|
||||
for (name in interfaces.keys) {
|
||||
var addrs = interfaces[name]
|
||||
System.print(addrs is List) // expect: true
|
||||
|
||||
for (addr in addrs) {
|
||||
System.print(addr is Map) // expect: true
|
||||
System.print(addr.containsKey("family")) // expect: true
|
||||
System.print(addr.containsKey("address")) // expect: true
|
||||
System.print(addr.containsKey("internal")) // expect: true
|
||||
System.print(addr.containsKey("netmask")) // expect: true
|
||||
System.print(addr.containsKey("mac")) // expect: true
|
||||
break
|
||||
}
|
||||
break
|
||||
}
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
import "sysinfo" for SysInfo
|
||||
|
||||
var uptime = SysInfo.uptime
|
||||
System.print(uptime is Num) // expect: true
|
||||
System.print(uptime > 0) // expect: true
|
||||
Vendored
+15
@@ -0,0 +1,15 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
import "timer" for Timer
|
||||
|
||||
var called = false
|
||||
|
||||
Timer.immediate {
|
||||
called = true
|
||||
}
|
||||
|
||||
System.print(called) // expect: false
|
||||
|
||||
Timer.sleep(1)
|
||||
|
||||
System.print(called) // expect: true
|
||||
Vendored
+20
@@ -0,0 +1,20 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
import "timer" for Timer, TimerHandle
|
||||
|
||||
var count = 0
|
||||
var handle = Timer.interval(1) {
|
||||
count = count + 1
|
||||
}
|
||||
|
||||
System.print(handle is TimerHandle) // expect: true
|
||||
System.print(handle.isActive) // expect: true
|
||||
|
||||
Timer.sleep(100)
|
||||
handle.stop()
|
||||
|
||||
System.print(count > 0) // expect: true
|
||||
System.print(handle.isActive) // expect: false
|
||||
|
||||
|
||||
System.print(count) // nontest
|
||||
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
import "timer" for Timer
|
||||
|
||||
Timer.sleep(10)
|
||||
System.print("after sleep") // expect: after sleep
|
||||
Vendored
+11
@@ -0,0 +1,11 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
import "udp" for UdpSocket
|
||||
|
||||
var socket = UdpSocket.new()
|
||||
socket.bind("127.0.0.1", 0)
|
||||
|
||||
System.print(socket.localAddress) // expect: 127.0.0.1
|
||||
System.print(socket.localPort > 0) // expect: true
|
||||
|
||||
socket.close()
|
||||
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
import "udp" for UdpSocket
|
||||
|
||||
var socket = UdpSocket.new()
|
||||
socket.bind("0.0.0.0", 0)
|
||||
socket.setBroadcast(true)
|
||||
System.print("broadcast enabled") // expect: broadcast enabled
|
||||
socket.close()
|
||||
Vendored
+30
@@ -0,0 +1,30 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
import "udp" for UdpSocket
|
||||
import "timer" for Timer
|
||||
import "scheduler" for Scheduler
|
||||
|
||||
var server = UdpSocket.new()
|
||||
server.bind("127.0.0.1", 0)
|
||||
var serverPort = server.localPort
|
||||
|
||||
var received = null
|
||||
|
||||
Scheduler.add {
|
||||
received = server.receive()
|
||||
server.close()
|
||||
}
|
||||
|
||||
var client = UdpSocket.new()
|
||||
client.bind("127.0.0.1", 0)
|
||||
|
||||
Timer.immediate {
|
||||
client.send("test", "127.0.0.1", serverPort)
|
||||
client.close()
|
||||
}
|
||||
|
||||
Timer.sleep(100)
|
||||
|
||||
System.print(received != null) // expect: true
|
||||
System.print(received[0]) // expect: test
|
||||
System.print(received[1]) // expect: 127.0.0.1
|
||||
Reference in New Issue
Block a user