Skip to content

Commit

Permalink
test: fix test for windows with conditional compile
Browse files Browse the repository at this point in the history
  • Loading branch information
gtn1024 committed Sep 27, 2024
1 parent 199cee4 commit 6db1ce5
Showing 1 changed file with 35 additions and 8 deletions.
43 changes: 35 additions & 8 deletions src/cjdotenv_test.cj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ import std.unittest.testmacro.*
import std.os.*
import std.collection.*

@When[os == "Windows"]
let emptyString = None

@When[os != "Windows"]
let emptyString = ""

func clearenv() {
for (key in envVars().keys()) {
removeEnv(key)
Expand Down Expand Up @@ -105,11 +111,18 @@ func testPlain() {
expectedValues["OPTION_C"] = "3"
expectedValues["OPTION_D"] = "4"
expectedValues["OPTION_E"] = "5"
expectedValues["OPTION_F"] = ""
expectedValues["OPTION_G"] = ""
expectedValues["OPTION_F"] = emptyString
expectedValues["OPTION_G"] = emptyString
expectedValues["OPTION_H"] = "1 2"

@Expect(envVars().size, 8)
var expected = 0
for ((_, v) in expectedValues) {
if (v != None) {
expected++
}
}

@Expect(envVars().size, expected)
for ((k, v) in expectedValues) {
@Expect(getEnv(k), v)
}
Expand All @@ -124,19 +137,26 @@ func testQuoted() {
let expectedValues = HashMap<String, ?String>()
expectedValues["OPTION_A"] = "1"
expectedValues["OPTION_B"] = "2"
expectedValues["OPTION_C"] = ""
expectedValues["OPTION_C"] = emptyString
expectedValues["OPTION_D"] = "\\n"
expectedValues["OPTION_E"] = "1"
expectedValues["OPTION_F"] = "2"
expectedValues["OPTION_G"] = ""
expectedValues["OPTION_G"] = emptyString
expectedValues["OPTION_H"] = "\n"
expectedValues["OPTION_I"] = "echo 'asd'"
expectedValues["OPTION_J"] = "line 1\nline 2"
expectedValues["OPTION_K"] = "line one\nthis is \\'quoted\\'\none more line"
expectedValues["OPTION_L"] = "line 1\nline 2"
expectedValues["OPTION_M"] = "line one\nthis is \"quoted\"\none more line"

@Expect(envVars().size, 13)
var expected = 0
for ((_, v) in expectedValues) {
if (v != None) {
expected++
}
}

@Expect(envVars().size, expected)
for ((k, v) in expectedValues) {
@Expect(getEnv(k), v)
}
Expand All @@ -153,7 +173,7 @@ func testSubstitutions() {
expectedValues["OPTION_B"] = "1"
expectedValues["OPTION_C"] = "1"
expectedValues["OPTION_D"] = "11"
expectedValues["OPTION_E"] = ""
expectedValues["OPTION_E"] = emptyString
expectedValues["OPTION_F"] = "default"
expectedValues["OPTION_G"] = "default"
expectedValues["OPTION_H"] = "-default"
Expand All @@ -164,7 +184,14 @@ func testSubstitutions() {
expectedValues["OPTION_N"] = "default"
expectedValues["OPTION_M"] = "default"

@Expect(envVars().size, 14)
var expected = 0
for ((_, v) in expectedValues) {
if (v != None) {
expected++
}
}

@Expect(envVars().size, expected)
for ((k, v) in expectedValues) {
@Expect(getEnv(k), v)
}
Expand Down

0 comments on commit 6db1ce5

Please sign in to comment.