Skip to content

Commit 39d5ea7

Browse files
authored
Merge pull request #12 from scala/simple-examples
Replace big example with simple examples
2 parents 7a53342 + 9a25c74 commit 39d5ea7

16 files changed

+98
-224
lines changed

.github/workflows/test.yaml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Test examples
2+
3+
on: push
4+
5+
jobs:
6+
test:
7+
name: Test examples
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Check out code
11+
uses: actions/checkout@v3
12+
with:
13+
fetch-depth: 0
14+
15+
- uses: coursier/[email protected]
16+
17+
- name: Setup Scala CLI
18+
uses: VirtusLab/scala-cli-setup@main
19+
20+
- name: Run test examples
21+
run: |
22+
cd examples
23+
for file in *.sc
24+
do
25+
scala-cli "$file"
26+
done
27+
28+
- name: Run examples of tests
29+
run: |
30+
cd examples
31+
for file in *.test.scala
32+
do
33+
scala-cli test "$file"
34+
done

example/Main.scala

Lines changed: 0 additions & 25 deletions
This file was deleted.

example/git/Commit.scala

Lines changed: 0 additions & 17 deletions
This file was deleted.

example/git/Contributor.scala

Lines changed: 0 additions & 3 deletions
This file was deleted.

example/git/Lang.scala

Lines changed: 0 additions & 35 deletions
This file was deleted.

example/git/Repo.scala

Lines changed: 0 additions & 95 deletions
This file was deleted.

example/test/RepoTest.scala

Lines changed: 0 additions & 49 deletions
This file was deleted.

examples/DirGetTotalSize.sc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//> using toolkit "latest"
2+
3+
val totalSize = os.walk.stream.attrs(os.pwd)
4+
.collect { case (path, attrs) if attrs.isFile => attrs.size }
5+
.sum
6+
7+
println(totalSize)

examples/FileReadText.sc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
//> using toolkit "latest"
2+
3+
val text = os.read(os.pwd / "resources" / "File.txt")
4+
println(text)

examples/JsonReading.sc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//> using toolkit "latest"
2+
3+
import upickle.default._
4+
5+
case class PetOwner(name: String, pet: String) derives ReadWriter
6+
val jsonString = """{"name": "Peter", "pet": "Toolkitty"}"""
7+
val petOwner: PetOwner = read[PetOwner](jsonString)
8+
9+
println(petOwner)

examples/JsonWriting.sc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//> using toolkit "latest"
2+
3+
import upickle.default._
4+
5+
case class PetOwner(name: String, pet: String) derives ReadWriter
6+
val petOwner = PetOwner("Peter", "Toolkitty")
7+
val json = write(petOwner)
8+
9+
println(json)

examples/RequestGet.sc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//> using toolkit "latest"
2+
3+
import sttp.client4.quick.*
4+
5+
val request = quickRequest.get(uri"https://httpbin.org/get")
6+
val response = request.send()
7+
8+
println(response)

examples/RequestPost.sc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//> using toolkit "latest"
2+
3+
import sttp.client4.quick.*
4+
5+
val response = quickRequest
6+
.post(uri"https://example.com/")
7+
.body("Lorem ipsum")
8+
.send()
9+
10+
println(response)

examples/SimpleTest.test.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//> using toolkit "latest"
2+
3+
class MathSuite extends munit.FunSuite {
4+
test("addition") {
5+
assert(1 + 1 == 2)
6+
}
7+
8+
test("read a missing file") {
9+
val missingFile = os.pwd / "missing.txt"
10+
intercept[java.nio.file.NoSuchFileException] {
11+
os.read(missingFile)
12+
}
13+
}
14+
}

examples/resources/File.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Test Test
2+
Foo Bar

examples/resources/File2.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Foo Foo

0 commit comments

Comments
 (0)