Skip to content

Commit

Permalink
[test/ysh-every-string] New test for string literal syntax
Browse files Browse the repository at this point in the history
- OSH vs. YSH
- stripped multi-line vs. regular non-stripped
- command vs. expression mode

Still need J8 strings in expression mode.

And J8 strings need single quotes ''.
  • Loading branch information
Andy C committed Jan 3, 2024
1 parent a4b246b commit a0e7ce6
Showing 1 changed file with 177 additions and 0 deletions.
177 changes: 177 additions & 0 deletions test/ysh-every-string.sh
@@ -0,0 +1,177 @@
#!/usr/bin/env bash
#
# Use every kind of YSH string
#
# Usage:
# test/ysh-every-string.sh <function name>

set -o nounset
set -o pipefail
set -o errexit

OSH=${OSH:-bin/osh}
YSH=${YSH:-bin/ysh}

# Disable for YSH
#shopt -s parse_sh_arith
source test/common.sh # run-test-funcs

# OSH and YSH
test-legacy-osh-ysh() {
for sh in $OSH $YSH; do
log " test-legacy with $sh"

$sh <<'EOF'
echo 'foo
---'
echo "foo
---"
echo $'fo\x6f
---'
#echo u'fooz
#---'
EOF
done
}

test-legacy-expr() {
for sh in $YSH; do
$sh <<'EOF'
var x = 'foo
---'
echo $x
var x = "foo
---"
echo $x
# I guess this is useful for refactoring
var x = $'fo\x6f
---'
echo $x
EOF
done
}

test-legacy-multiline() {
### double-quoted is allowed to be multi-line in YSH

for sh in $YSH; do
$sh <<'EOF'
echo """
foo
---
"""
var x = """
foo
---
"""
echo $x
EOF
done
}

test-j8() {
### J8 strings are allowed in YSH

#for sh in $OSH $YSH; do
for sh in $YSH; do
$sh <<'EOF'
# Command mode
echo u'fo\u{6f}
---'
echo b'foo
---'
# Leading indent of ---
echo u'''
fo\u{6f}
---
'''
echo b'''
fo\u{6f}
---
'''
# Expression mode
#var x = u'fo\u{6f}
#---'
#echo $x
EOF
done
}

test-raw() {
### r prefix for raw is allowed in YSH

#for sh in $OSH $YSH; do
for sh in $YSH; do
$sh <<'EOF'
# Command mode
echo 'foo
---'
echo r'foo
---'
echo '''
foo
---
'''
echo r'''
foo
---
'''
# Expression mode
var x = 'foo
---'
echo $x
var x = r'foo
---'
echo $x
var x = '''
foo
---
'''
echo $x
var x = r'''
foo
---
'''
echo $x
EOF
done
}

soil-run-py() {
run-test-funcs
}

soil-run-cpp() {
ninja _bin/cxx-asan/osh
SH=_bin/cxx-asan/osh run-test-funcs
}

run-for-release() {
run-other-suite-for-release ysh-every-string run-test-funcs
}

"$@"

0 comments on commit a0e7ce6

Please sign in to comment.