mirror of
https://github.com/mikefarah/yq.git
synced 2024-11-12 13:48:06 +00:00
c8815f5ab9
* WIP: adding CSV decoder * Adding CSV decoder * Added CSV roundtrip * Fixing from review
208 lines
2.9 KiB
Bash
Executable File
208 lines
2.9 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
setUp() {
|
|
rm test*.yml || true
|
|
}
|
|
|
|
testOutputJsonDeprecated() {
|
|
cat >test.yml <<EOL
|
|
a: {b: ["cat"]}
|
|
EOL
|
|
|
|
read -r -d '' expected << EOM
|
|
{
|
|
"a": {
|
|
"b": [
|
|
"cat"
|
|
]
|
|
}
|
|
}
|
|
EOM
|
|
|
|
X=$(./yq e -j test.yml)
|
|
assertEquals "$expected" "$X"
|
|
|
|
X=$(./yq ea -j test.yml)
|
|
assertEquals "$expected" "$X"
|
|
}
|
|
|
|
testOutputJson() {
|
|
cat >test.yml <<EOL
|
|
a: {b: ["cat"]}
|
|
EOL
|
|
|
|
read -r -d '' expected << EOM
|
|
{
|
|
"a": {
|
|
"b": [
|
|
"cat"
|
|
]
|
|
}
|
|
}
|
|
EOM
|
|
|
|
X=$(./yq e --output-format=json test.yml)
|
|
assertEquals "$expected" "$X"
|
|
|
|
X=$(./yq ea --output-format=json test.yml)
|
|
assertEquals "$expected" "$X"
|
|
}
|
|
|
|
testOutputJsonShort() {
|
|
cat >test.yml <<EOL
|
|
a: {b: ["cat"]}
|
|
EOL
|
|
|
|
read -r -d '' expected << EOM
|
|
{
|
|
"a": {
|
|
"b": [
|
|
"cat"
|
|
]
|
|
}
|
|
}
|
|
EOM
|
|
|
|
X=$(./yq e -o=j test.yml)
|
|
assertEquals "$expected" "$X"
|
|
|
|
X=$(./yq ea -o=j test.yml)
|
|
assertEquals "$expected" "$X"
|
|
}
|
|
|
|
testOutputProperties() {
|
|
cat >test.yml <<EOL
|
|
a: {b: {c: ["cat"]}}
|
|
EOL
|
|
|
|
read -r -d '' expected << EOM
|
|
a.b.c.0 = cat
|
|
EOM
|
|
|
|
X=$(./yq e --output-format=props test.yml)
|
|
assertEquals "$expected" "$X"
|
|
|
|
X=$(./yq ea --output-format=props test.yml)
|
|
assertEquals "$expected" "$X"
|
|
}
|
|
|
|
testOutputPropertiesShort() {
|
|
cat >test.yml <<EOL
|
|
a: {b: {c: ["cat"]}}
|
|
EOL
|
|
|
|
read -r -d '' expected << EOM
|
|
a.b.c.0 = cat
|
|
EOM
|
|
|
|
X=$(./yq e -o=p test.yml)
|
|
assertEquals "$expected" "$X"
|
|
|
|
X=$(./yq ea -o=p test.yml)
|
|
assertEquals "$expected" "$X"
|
|
}
|
|
|
|
testOutputCSV() {
|
|
cat >test.yml <<EOL
|
|
- fruit: apple
|
|
yumLevel: 5
|
|
- fruit: banana
|
|
yumLevel: 4
|
|
EOL
|
|
|
|
read -r -d '' expected << EOM
|
|
fruit,yumLevel
|
|
apple,5
|
|
banana,4
|
|
EOM
|
|
|
|
X=$(./yq -o=c test.yml)
|
|
assertEquals "$expected" "$X"
|
|
|
|
X=$(./yq ea -o=csv test.yml)
|
|
assertEquals "$expected" "$X"
|
|
}
|
|
|
|
testOutputTSV() {
|
|
cat >test.yml <<EOL
|
|
- fruit: apple
|
|
yumLevel: 5
|
|
- fruit: banana
|
|
yumLevel: 4
|
|
EOL
|
|
|
|
read -r -d '' expected << EOM
|
|
fruit yumLevel
|
|
apple 5
|
|
banana 4
|
|
EOM
|
|
|
|
X=$(./yq -o=t test.yml)
|
|
assertEquals "$expected" "$X"
|
|
|
|
X=$(./yq ea -o=tsv test.yml)
|
|
assertEquals "$expected" "$X"
|
|
}
|
|
|
|
testOutputXml() {
|
|
cat >test.yml <<EOL
|
|
a: {b: {c: ["cat"]}}
|
|
EOL
|
|
|
|
read -r -d '' expected << EOM
|
|
<a>
|
|
<b>
|
|
<c>cat</c>
|
|
</b>
|
|
</a>
|
|
EOM
|
|
|
|
X=$(./yq e --output-format=xml test.yml)
|
|
assertEquals "$expected" "$X"
|
|
|
|
X=$(./yq ea --output-format=xml test.yml)
|
|
assertEquals "$expected" "$X"
|
|
}
|
|
|
|
testOutputXmlShort() {
|
|
cat >test.yml <<EOL
|
|
a: {b: {c: ["cat"]}}
|
|
EOL
|
|
|
|
read -r -d '' expected << EOM
|
|
<a>
|
|
<b>
|
|
<c>cat</c>
|
|
</b>
|
|
</a>
|
|
EOM
|
|
|
|
X=$(./yq e --output-format=x test.yml)
|
|
assertEquals "$expected" "$X"
|
|
|
|
X=$(./yq ea --output-format=x test.yml)
|
|
assertEquals "$expected" "$X"
|
|
}
|
|
|
|
testOutputXmComplex() {
|
|
cat >test.yml <<EOL
|
|
a: {b: {c: ["cat", "dog"], +f: meow}}
|
|
EOL
|
|
|
|
read -r -d '' expected << EOM
|
|
<a>
|
|
<b f="meow">
|
|
<c>cat</c>
|
|
<c>dog</c>
|
|
</b>
|
|
</a>
|
|
EOM
|
|
|
|
X=$(./yq e --output-format=x test.yml)
|
|
assertEquals "$expected" "$X"
|
|
|
|
X=$(./yq ea --output-format=x test.yml)
|
|
assertEquals "$expected" "$X"
|
|
}
|
|
|
|
source ./scripts/shunit2 |