Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/contains_cli/contains_cli.howl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(do
(let (needle (cli_args 0) path (cli_args 1))
(if (or (= needle "") (= path ""))
(if (or (blank needle) (blank path))
(do (print "Usage: contains_cli <needle> <file>") (exit 2))
(try_let (s (read_text path))
(catch e (do (print "error=" e) (exit 2)))
Expand Down
2 changes: 1 addition & 1 deletion apps/ends_cli/ends_cli.howl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(do
(let (suffix (cli_args 0) path (cli_args 1))
(if (or (= suffix "") (= path ""))
(if (or (blank suffix) (blank path))
(do (print "Usage: ends_cli <suffix> <file>") (exit 2))
(try_let (s (read_text path))
(catch e (do (print "error=" e) (exit 2)))
Expand Down
2 changes: 1 addition & 1 deletion apps/file_transform/file_transform.howl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(do
(let (in (cli_args 0) out (cli_args 1))
(if (or (= in "") (= out ""))
(if (or (blank in) (blank out))
(do (print "Usage: file_transform <in.csv> <out.jsonl>") (exit 2))
(try_let (raw (read_file in))
(catch e (do (print "error=" e) (exit 2)))
Expand Down
8 changes: 8 additions & 0 deletions apps/icontains_cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# icontains_cli

Case-insensitive substring search using `to_lower` + `str_contains`.

```bash
go run ../../howlframe.go -compile-bc icontains_cli.howl
go run ../../howlframe.go -run-bc -allow-caps filesystem icontains_cli.howl.bc.bin beta sample.txt
```
9 changes: 9 additions & 0 deletions apps/icontains_cli/icontains_cli.howl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
(do
(let (needle (cli_args 0) path (cli_args 1))
(if (or (blank needle) (blank path))
(do (print "Usage: icontains_cli <needle> <file>") (exit 2))
(try_let (s (read_text path))
(catch e (do (print "error=" e) (exit 2)))
(if (str_contains (to_lower s) (to_lower needle))
(do (print "FOUND") (exit 0))
(do (print "MISSING") (exit 1)))))))
34 changes: 34 additions & 0 deletions apps/icontains_cli/icontains_cli_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package icontains_cli_test

import (
"os"
"os/exec"
"strings"
"testing"
)

func TestIContainsCLI(t *testing.T) {
cmd := exec.Command("go", "run", "../../howlframe.go", "-compile-bc", "icontains_cli.howl")
cmd.Dir = "."
if err := cmd.Run(); err != nil {
t.Fatalf("compile: %v", err)
}
os.WriteFile("sample.txt", []byte("Alpha Beta Gamma\n"), 0644)
defer os.Remove("sample.txt")

cmd = exec.Command("go", "run", "../../howlframe.go", "-run-bc", "-allow-caps", "filesystem",
"icontains_cli.howl.bc.bin", "beta", "sample.txt")
cmd.Dir = "."
out, err := cmd.CombinedOutput()
if err != nil || !strings.Contains(string(out), "FOUND") {
t.Fatalf("found: %v %s", err, out)
}

cmd = exec.Command("go", "run", "../../howlframe.go", "-run-bc", "-allow-caps", "filesystem",
"icontains_cli.howl.bc.bin", "delta", "sample.txt")
cmd.Dir = "."
out, err = cmd.CombinedOutput()
if err == nil || !strings.Contains(string(out), "MISSING") {
t.Fatalf("missing: err=%v out=%s", err, out)
}
}
8 changes: 8 additions & 0 deletions apps/lower_cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# lower_cli

Lowercase text via native `to_lower` CONVERT.

```bash
go run ../../howlframe.go -compile-bc lower_cli.howl
go run ../../howlframe.go -run-bc lower_cli.howl.bc.bin "Hello World"
```
5 changes: 5 additions & 0 deletions apps/lower_cli/lower_cli.howl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(do
(let (s (cli_args 0))
(if (blank s)
(do (print "Usage: lower_cli <text>") (exit 2))
(do (print (to_lower s)) (exit 0)))))
30 changes: 30 additions & 0 deletions apps/lower_cli/lower_cli_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package lower_cli_test

import (
"os/exec"
"strings"
"testing"
)

func TestLowerCLI(t *testing.T) {
cmd := exec.Command("go", "run", "../../howlframe.go", "-compile-bc", "lower_cli.howl")
cmd.Dir = "."
if err := cmd.Run(); err != nil {
t.Fatalf("compile: %v", err)
}

cmd = exec.Command("go", "run", "../../howlframe.go", "-run-bc",
"lower_cli.howl.bc.bin", "Hello World")
cmd.Dir = "."
out, err := cmd.CombinedOutput()
if err != nil || !strings.Contains(string(out), "hello world") {
t.Fatalf("lower: %v %s", err, out)
}

cmd = exec.Command("go", "run", "../../howlframe.go", "-run-bc", "lower_cli.howl.bc.bin")
cmd.Dir = "."
out, err = cmd.CombinedOutput()
if err == nil || !strings.Contains(string(out), "Usage:") {
t.Fatalf("usage: err=%v out=%s", err, out)
}
}
2 changes: 1 addition & 1 deletion apps/starts_cli/starts_cli.howl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(do
(let (prefix (cli_args 0) path (cli_args 1))
(if (or (= prefix "") (= path ""))
(if (or (blank prefix) (blank path))
(do (print "Usage: starts_cli <prefix> <file>") (exit 2))
(try_let (s (read_text path))
(catch e (do (print "error=" e) (exit 2)))
Expand Down
2 changes: 1 addition & 1 deletion apps/template_cli/template_cli.howl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(do
(let (path (cli_args 0) key (cli_args 1) val (cli_args 2))
(if (or (= path "") (= key "") (= val ""))
(if (or (blank path) (blank key) (blank val))
(do (print "Usage: template_cli <file> <key> <value>") (exit 2))
(try_let (s (read_text path))
(catch e (do (print "error=" e) (exit 2)))
Expand Down
8 changes: 8 additions & 0 deletions apps/trim_cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# trim_cli

Trim surrounding whitespace via native `str_trim` CONVERT.

```bash
go run ../../howlframe.go -compile-bc trim_cli.howl
go run ../../howlframe.go -run-bc trim_cli.howl.bc.bin " hello "
```
5 changes: 5 additions & 0 deletions apps/trim_cli/trim_cli.howl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(do
(let (s (cli_args 0))
(if (blank s)
(do (print "Usage: trim_cli <text>") (exit 2))
(do (print (str_trim s)) (exit 0)))))
30 changes: 30 additions & 0 deletions apps/trim_cli/trim_cli_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package trim_cli_test

import (
"os/exec"
"strings"
"testing"
)

func TestTrimCLI(t *testing.T) {
cmd := exec.Command("go", "run", "../../howlframe.go", "-compile-bc", "trim_cli.howl")
cmd.Dir = "."
if err := cmd.Run(); err != nil {
t.Fatalf("compile: %v", err)
}

cmd = exec.Command("go", "run", "../../howlframe.go", "-run-bc",
"trim_cli.howl.bc.bin", " hello ")
cmd.Dir = "."
out, err := cmd.CombinedOutput()
if err != nil || strings.TrimSpace(string(out)) != "hello" {
t.Fatalf("trim: %v %s", err, out)
}

cmd = exec.Command("go", "run", "../../howlframe.go", "-run-bc", "trim_cli.howl.bc.bin")
cmd.Dir = "."
out, err = cmd.CombinedOutput()
if err == nil || !strings.Contains(string(out), "Usage:") {
t.Fatalf("usage: err=%v out=%s", err, out)
}
}
8 changes: 8 additions & 0 deletions apps/upper_cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# upper_cli

Uppercase text via native `to_upper` CONVERT.

```bash
go run ../../howlframe.go -compile-bc upper_cli.howl
go run ../../howlframe.go -run-bc upper_cli.howl.bc.bin "Hello World"
```
5 changes: 5 additions & 0 deletions apps/upper_cli/upper_cli.howl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(do
(let (s (cli_args 0))
(if (blank s)
(do (print "Usage: upper_cli <text>") (exit 2))
(do (print (to_upper s)) (exit 0)))))
30 changes: 30 additions & 0 deletions apps/upper_cli/upper_cli_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package upper_cli_test

import (
"os/exec"
"strings"
"testing"
)

func TestUpperCLI(t *testing.T) {
cmd := exec.Command("go", "run", "../../howlframe.go", "-compile-bc", "upper_cli.howl")
cmd.Dir = "."
if err := cmd.Run(); err != nil {
t.Fatalf("compile: %v", err)
}

cmd = exec.Command("go", "run", "../../howlframe.go", "-run-bc",
"upper_cli.howl.bc.bin", "Hello World")
cmd.Dir = "."
out, err := cmd.CombinedOutput()
if err != nil || !strings.Contains(string(out), "HELLO WORLD") {
t.Fatalf("upper: %v %s", err, out)
}

cmd = exec.Command("go", "run", "../../howlframe.go", "-run-bc", "upper_cli.howl.bc.bin")
cmd.Dir = "."
out, err = cmd.CombinedOutput()
if err == nil || !strings.Contains(string(out), "Usage:") {
t.Fatalf("usage: err=%v out=%s", err, out)
}
}
29 changes: 29 additions & 0 deletions benchmarks/real_apps/icontains_cli/go/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package main

import (
"fmt"
"os"
"strings"
)

func main() {
os.Exit(run(os.Args[1:]))
}

func run(args []string) int {
if len(args) < 2 || args[0] == "" || args[1] == "" {
fmt.Println("Usage: icontains_cli <needle> <file>")
return 2
}
raw, err := os.ReadFile(args[1])
if err != nil {
fmt.Printf("error=%v\n", err)
return 2
}
if strings.Contains(strings.ToLower(string(raw)), strings.ToLower(args[0])) {
fmt.Println("FOUND")
return 0
}
fmt.Println("MISSING")
return 1
}
25 changes: 25 additions & 0 deletions benchmarks/real_apps/icontains_cli/node/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env node
const fs = require("fs");

function main(argv) {
const args = argv.slice(2);
if (args.length < 2 || args[0] === "" || args[1] === "") {
console.log("Usage: icontains_cli <needle> <file>");
return 2;
}
let s;
try {
s = fs.readFileSync(args[1], "utf8");
} catch (e) {
console.log("error=" + e);
return 2;
}
if (s.toLowerCase().includes(args[0].toLowerCase())) {
console.log("FOUND");
return 0;
}
console.log("MISSING");
return 1;
}

process.exit(main(process.argv));
24 changes: 24 additions & 0 deletions benchmarks/real_apps/icontains_cli/python/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env python3
import sys


def main(argv: list[str]) -> int:
if len(argv) < 3 or argv[1] == "" or argv[2] == "":
print("Usage: icontains_cli <needle> <file>")
return 2
needle, path = argv[1], argv[2]
try:
with open(path, encoding="utf-8") as f:
s = f.read()
except OSError as e:
print(f"error={e}")
return 2
if needle.lower() in s.lower():
print("FOUND")
return 0
print("MISSING")
return 1


if __name__ == "__main__":
raise SystemExit(main(sys.argv))
20 changes: 20 additions & 0 deletions benchmarks/real_apps/lower_cli/go/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package main

import (
"fmt"
"os"
"strings"
)

func main() {
os.Exit(run(os.Args[1:]))
}

func run(args []string) int {
if len(args) < 1 || args[0] == "" {
fmt.Println("Usage: lower_cli <text>")
return 2
}
fmt.Println(strings.ToLower(args[0]))
return 0
}
13 changes: 13 additions & 0 deletions benchmarks/real_apps/lower_cli/node/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env node

function main(argv) {
const args = argv.slice(2);
if (args.length < 1 || args[0] === "") {
console.log("Usage: lower_cli <text>");
return 2;
}
console.log(args[0].toLowerCase());
return 0;
}

process.exit(main(process.argv));
14 changes: 14 additions & 0 deletions benchmarks/real_apps/lower_cli/python/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env python3
import sys


def main(argv: list[str]) -> int:
if len(argv) < 2 or argv[1] == "":
print("Usage: lower_cli <text>")
return 2
print(argv[1].lower())
return 0


if __name__ == "__main__":
raise SystemExit(main(sys.argv))
Loading
Loading