commit everything

This commit is contained in:
bruno 2023-03-08 16:56:26 -05:00
parent 2b606f9010
commit 80569850c4
2 changed files with 52 additions and 0 deletions

11
tests/test_execCmd.nim Normal file
View File

@ -0,0 +1,11 @@
import osproc
proc runCommand(cmd: string) =
let (output, exitCode) = execCmdEx(cmd)
echo "Command:", cmd
echo "Output:", output
echo "Exit code:", exitCode
runCommand("echo Hello")
runCommand("ls -l")
runCommand("invalid command")

41
tests/test_object.nim Normal file
View File

@ -0,0 +1,41 @@
type
PortState = enum Open, Closed
PortItem = object
port: int
state: PortState
# A simple container for PortItems
type
PortList = seq[PortItem]
# Add a new port to the list
proc addPort(portList: var PortList; newPort: PortItem) =
portList.add(newPort)
# Modify an existing port in the list
proc modifyPort(portList: var PortList; portNum: int; newState: PortState) =
for i in 0..<portList.len:
if portList[i].port == portNum:
portList[i].state = newState
return
echo "Port not found."
# Delete a port from the list
proc deletePort(portList: var PortList; portNum: int) =
for i in 0..<portList.len:
if portList[i].port == portNum:
portList.del(i)
return
echo "Port not found."
# Sample usage
var ports: PortList
addPort(ports, PortItem(port: 80, state: PortState.Open))
addPort(ports, PortItem(port: 443, state: PortState.Closed))
echo ports
modifyPort(ports, 80, PortState.Closed)
echo ports
deletePort(ports, 443)
echo ports