2023-03-08 23:17:19 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
setUp() {
|
|
|
|
rm test*.yml 2>/dev/null || true
|
|
|
|
rm test*.json 2>/dev/null || true
|
|
|
|
rm test*.properties 2>/dev/null || true
|
|
|
|
rm test*.csv 2>/dev/null || true
|
|
|
|
rm test*.tsv 2>/dev/null || true
|
|
|
|
rm test*.xml 2>/dev/null || true
|
|
|
|
}
|
|
|
|
|
|
|
|
testInputJson() {
|
|
|
|
cat >test.json <<EOL
|
|
|
|
{ "mike" : { "things": "cool" } }
|
|
|
|
EOL
|
|
|
|
|
|
|
|
read -r -d '' expected << EOM
|
2023-03-15 02:22:58 +00:00
|
|
|
{
|
|
|
|
"mike": {
|
|
|
|
"things": "cool"
|
|
|
|
}
|
|
|
|
}
|
2023-03-08 23:17:19 +00:00
|
|
|
EOM
|
|
|
|
|
|
|
|
X=$(./yq test.json)
|
|
|
|
assertEquals "$expected" "$X"
|
|
|
|
|
|
|
|
X=$(./yq ea test.json)
|
|
|
|
assertEquals "$expected" "$X"
|
|
|
|
}
|
|
|
|
|
2023-03-15 02:22:58 +00:00
|
|
|
testInputJsonOutputYaml() {
|
|
|
|
cat >test.json <<EOL
|
|
|
|
{ "mike" : { "things": "cool" } }
|
|
|
|
EOL
|
|
|
|
|
|
|
|
read -r -d '' expected << EOM
|
|
|
|
mike:
|
|
|
|
things: cool
|
|
|
|
EOM
|
|
|
|
|
|
|
|
X=$(./yq test.json -oy)
|
|
|
|
assertEquals "$expected" "$X"
|
|
|
|
|
|
|
|
X=$(./yq ea test.json -oy)
|
|
|
|
assertEquals "$expected" "$X"
|
|
|
|
}
|
|
|
|
|
2023-03-08 23:17:19 +00:00
|
|
|
testInputProperties() {
|
|
|
|
cat >test.properties <<EOL
|
|
|
|
mike.things = hello
|
|
|
|
EOL
|
|
|
|
|
|
|
|
read -r -d '' expected << EOM
|
2023-03-15 02:22:58 +00:00
|
|
|
mike.things = hello
|
2023-03-08 23:17:19 +00:00
|
|
|
EOM
|
|
|
|
|
|
|
|
X=$(./yq e test.properties)
|
|
|
|
assertEquals "$expected" "$X"
|
|
|
|
|
2023-03-15 02:22:58 +00:00
|
|
|
X=$(./yq test.properties)
|
|
|
|
assertEquals "$expected" "$X"
|
|
|
|
|
2023-03-08 23:17:19 +00:00
|
|
|
X=$(./yq ea test.properties)
|
|
|
|
assertEquals "$expected" "$X"
|
|
|
|
}
|
|
|
|
|
|
|
|
testInputPropertiesGitHubAction() {
|
|
|
|
cat >test.properties <<EOL
|
|
|
|
mike.things = hello
|
|
|
|
EOL
|
|
|
|
|
|
|
|
read -r -d '' expected << EOM
|
2023-03-15 02:22:58 +00:00
|
|
|
mike.things = hello
|
2023-03-08 23:17:19 +00:00
|
|
|
EOM
|
|
|
|
|
|
|
|
X=$(cat /dev/null | ./yq e test.properties)
|
|
|
|
assertEquals "$expected" "$X"
|
|
|
|
|
|
|
|
X=$(cat /dev/null | ./yq ea test.properties)
|
|
|
|
assertEquals "$expected" "$X"
|
|
|
|
}
|
|
|
|
|
|
|
|
testInputCSV() {
|
|
|
|
cat >test.csv <<EOL
|
|
|
|
fruit,yumLevel
|
|
|
|
apple,5
|
|
|
|
banana,4
|
|
|
|
EOL
|
|
|
|
|
|
|
|
read -r -d '' expected << EOM
|
2023-03-15 02:22:58 +00:00
|
|
|
fruit,yumLevel
|
|
|
|
apple,5
|
|
|
|
banana,4
|
2023-03-08 23:17:19 +00:00
|
|
|
EOM
|
|
|
|
|
|
|
|
X=$(./yq e test.csv)
|
|
|
|
assertEquals "$expected" "$X"
|
|
|
|
|
|
|
|
X=$(./yq ea test.csv)
|
|
|
|
assertEquals "$expected" "$X"
|
|
|
|
}
|
|
|
|
|
|
|
|
testInputCSVUTF8() {
|
|
|
|
read -r -d '' expected << EOM
|
2023-03-15 02:22:58 +00:00
|
|
|
id,first,last
|
|
|
|
1,john,smith
|
|
|
|
1,jane,smith
|
2023-03-08 23:17:19 +00:00
|
|
|
EOM
|
|
|
|
|
|
|
|
X=$(./yq utf8.csv)
|
|
|
|
assertEquals "$expected" "$X"
|
|
|
|
}
|
|
|
|
|
|
|
|
testInputTSV() {
|
|
|
|
cat >test.tsv <<EOL
|
|
|
|
fruit yumLevel
|
|
|
|
apple 5
|
|
|
|
banana 4
|
|
|
|
EOL
|
|
|
|
|
|
|
|
read -r -d '' expected << EOM
|
2023-03-15 02:22:58 +00:00
|
|
|
fruit yumLevel
|
|
|
|
apple 5
|
|
|
|
banana 4
|
2023-03-08 23:17:19 +00:00
|
|
|
EOM
|
|
|
|
|
|
|
|
X=$(./yq e test.tsv)
|
|
|
|
assertEquals "$expected" "$X"
|
|
|
|
|
|
|
|
X=$(./yq ea test.tsv)
|
|
|
|
assertEquals "$expected" "$X"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
testInputXml() {
|
|
|
|
cat >test.xml <<EOL
|
|
|
|
<cat legs="4">BiBi</cat>
|
|
|
|
EOL
|
|
|
|
|
|
|
|
read -r -d '' expected << EOM
|
2023-03-15 02:22:58 +00:00
|
|
|
<cat legs="4">BiBi</cat>
|
2023-03-08 23:17:19 +00:00
|
|
|
EOM
|
|
|
|
|
|
|
|
X=$(./yq e test.xml)
|
|
|
|
assertEquals "$expected" "$X"
|
|
|
|
|
|
|
|
X=$(./yq ea test.xml)
|
|
|
|
assertEquals "$expected" "$X"
|
|
|
|
}
|
|
|
|
|
|
|
|
testInputXmlNamespaces() {
|
|
|
|
cat >test.xml <<EOL
|
|
|
|
<?xml version="1.0"?>
|
|
|
|
<map xmlns="some-namespace" xmlns:xsi="some-instance" xsi:schemaLocation="some-url">
|
|
|
|
</map>
|
|
|
|
EOL
|
|
|
|
|
|
|
|
read -r -d '' expected << EOM
|
2023-03-15 02:22:58 +00:00
|
|
|
<?xml version="1.0"?>
|
|
|
|
<map xmlns="some-namespace" xmlns:xsi="some-instance" xsi:schemaLocation="some-url"></map>
|
2023-03-08 23:17:19 +00:00
|
|
|
EOM
|
|
|
|
|
|
|
|
X=$(./yq e test.xml)
|
|
|
|
assertEquals "$expected" "$X"
|
|
|
|
|
|
|
|
X=$(./yq ea test.xml)
|
|
|
|
assertEquals "$expected" "$X"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
testInputXmlStrict() {
|
|
|
|
cat >test.xml <<EOL
|
|
|
|
<?xml version="1.0"?>
|
|
|
|
<!DOCTYPE root [
|
|
|
|
<!ENTITY writer "Catherine.">
|
|
|
|
<!ENTITY copyright "(r) Great">
|
|
|
|
]>
|
|
|
|
<root>
|
|
|
|
<item>&writer;©right;</item>
|
|
|
|
</root>
|
|
|
|
EOL
|
|
|
|
|
2023-03-15 02:22:58 +00:00
|
|
|
X=$(./yq --xml-strict-mode test.xml 2>&1)
|
2023-03-08 23:17:19 +00:00
|
|
|
assertEquals 1 $?
|
|
|
|
assertEquals "Error: bad file 'test.xml': XML syntax error on line 7: invalid character entity &writer;" "$X"
|
|
|
|
|
2023-03-15 02:22:58 +00:00
|
|
|
X=$(./yq ea --xml-strict-mode test.xml 2>&1)
|
2023-03-08 23:17:19 +00:00
|
|
|
assertEquals "Error: bad file 'test.xml': XML syntax error on line 7: invalid character entity &writer;" "$X"
|
|
|
|
}
|
|
|
|
|
|
|
|
testInputXmlGithubAction() {
|
|
|
|
cat >test.xml <<EOL
|
|
|
|
<cat legs="4">BiBi</cat>
|
|
|
|
EOL
|
|
|
|
|
|
|
|
read -r -d '' expected << EOM
|
2023-03-15 02:22:58 +00:00
|
|
|
<cat legs="4">BiBi</cat>
|
2023-03-08 23:17:19 +00:00
|
|
|
EOM
|
|
|
|
|
|
|
|
X=$(cat /dev/null | ./yq e test.xml)
|
|
|
|
assertEquals "$expected" "$X"
|
|
|
|
|
|
|
|
X=$(cat /dev/null | ./yq ea test.xml)
|
|
|
|
assertEquals "$expected" "$X"
|
|
|
|
}
|
|
|
|
|
|
|
|
source ./scripts/shunit2
|