Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #172 #342

Merged
merged 2 commits into from
Aug 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions core/desugarer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -643,11 +643,17 @@ class Desugarer {
desugar(ast->body, obj_level);
desugarParams(ast->params, obj_level);

} else if (dynamic_cast<const Import *>(ast_)) {
// Nothing to do.

} else if (dynamic_cast<const Importstr *>(ast_)) {
// Nothing to do.
} else if (auto *ast = dynamic_cast<Import *>(ast_)) {
// TODO(dcunnin): Abstract this into a template function if it becomes more common.
AST *file = ast->file;
desugar(file, obj_level);
ast->file = dynamic_cast<LiteralString*>(file);

} else if (auto *ast = dynamic_cast<Importstr *>(ast_)) {
// TODO(dcunnin): Abstract this into a template function if it becomes more common.
AST *file = ast->file;
desugar(file, obj_level);
ast->file = dynamic_cast<LiteralString*>(file);

} else if (auto *ast = dynamic_cast<InSuper *>(ast_)) {
desugar(ast->element, obj_level);
Expand Down
5 changes: 5 additions & 0 deletions core/string_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ limitations under the License.
/** Unparse the string. */
UString jsonnet_string_unparse(const UString &str, bool single);


// Note that the following two functions do not handle the quoting of ' and "
// inside verbatim strings because that quoting is reversible. Thus, that
// quoting is done at lexing time and undone again at pretty-printing time.

/** Escape special characters. */
UString jsonnet_string_escape(const UString &str, bool single);

Expand Down
3 changes: 2 additions & 1 deletion doc/language/spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ <h2 id="lexing">Lexing</h2>
first subsequent line that does not begin with <i>W</i>, and it is an error if this line does not
contain some optional whitespace followed by <code>|||</code>. The content of the string is the
concatenation of all the lines that began with <i>W</i> but with that prefix stripped. The line
ending style in the file is preserved in the string.</li>
ending style in the file is preserved in the string. This form cannot be used in
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A test for that would be nice.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

<code>import</code> statements.</li>
</ul>

<p>Double- and single-quoted strings are allowed to span multiple lines, in which case whatever
Expand Down
8 changes: 6 additions & 2 deletions examples/check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.

TEST_SUITE_NAME="${TEST_SUITE_NAME:-$0}"

cd $(dirname $0)

JSONNET_BIN="${JSONNET_BIN:-../jsonnet}"

source ../test_suite/tests.source
Expand Down Expand Up @@ -51,8 +55,8 @@ done
deinit

if [ "$FAILED" -eq 0 ] ; then
echo "All $EXECUTED examples executed correctly."
echo "$TEST_SUITE_NAME: All $EXECUTED tests executed correctly."
else
echo "$FAILED / $EXECUTED tests failed."
echo "$TEST_SUITE_NAME: $FAILED / $EXECUTED tests failed."
exit 1
fi
4 changes: 4 additions & 0 deletions examples/terraform/check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.

export TEST_SUITE_NAME="$0"

cd "$(dirname $0)"

export EXAMPLES_DIR="$PWD"

cd .. && ./check.sh
20 changes: 20 additions & 0 deletions test_suite/error.parse.import_text_block.jsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
Copyright 2017 Google Inc. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import |||
This is a paragraph of text, which is being used in the place of
a filename. That is quite unusual, and probably not intended.
|||
1 change: 1 addition & 0 deletions test_suite/error.parse.import_text_block.jsonnet.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
STATIC ERROR: error.parse.import_text_block.jsonnet:(17:8)-(20:3): Cannot use text blocks in import statements.
6 changes: 6 additions & 0 deletions test_suite/import.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,20 @@ limitations under the License.
// Can capture variables from another file.
std.assertEqual((import "lib/A_20_func.libsonnet")(), 20) &&

// Ensure string is quoted.
std.assertEqual((import "lib/\u0041_20_func.libsonnet")(), 20) &&

# Test single quoted string.
std.assertEqual((import 'lib/A_20_func.libsonnet')(), 20) &&
# The block string is hard to test because the filename would include a terminating \n

// Each import has its own environment, can't be overidden.
std.assertEqual(local A = 7; local lib = import "lib/A_20.libsonnet"; lib, 20) &&
std.assertEqual(local A = 7, lib = import "lib/A_20.libsonnet"; lib, 20) &&

std.assertEqual(importstr "lib/some_file.txt", "Hello World!\n") &&
std.assertEqual(importstr "lib/\u0073ome_file.txt", "Hello World!\n") &&

std.assertEqual(import "lib/rel_path.libsonnet", "rel_path") &&
std.assertEqual(import "lib/rel_path4.libsonnet", "rel_path") &&

Expand Down
6 changes: 4 additions & 2 deletions test_suite/run_fmt_idempotence_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

cd "$(dirname $0)"

source "tests.source"

# Enable next line to test the garbage collector
Expand Down Expand Up @@ -51,9 +53,9 @@ for TEST in *.jsonnet ../examples/*.jsonnet ../examples/terraform/*.jsonnet ../b
done

if [ $FAILED -eq 0 ] ; then
echo "All $EXECUTED test scripts pass."
echo "$0: All $EXECUTED test scripts pass."
else
echo "FAILED: $FAILED / $EXECUTED"
echo "$0: FAILED: $FAILED / $EXECUTED"
exit 1
fi

Expand Down
6 changes: 4 additions & 2 deletions test_suite/run_fmt_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

cd "$(dirname $0)"

source "tests.source"

# Enable next line to test the garbage collector
Expand Down Expand Up @@ -45,9 +47,9 @@ for TEST in *.jsonnet ../examples/*.jsonnet ../examples/terraform/*.jsonnet ../b
done

if [ $FAILED -eq 0 ] ; then
echo "All $EXECUTED test scripts pass."
echo "$0: All $EXECUTED test scripts pass."
else
echo "FAILED: $FAILED / $EXECUTED"
echo "$0: FAILED: $FAILED / $EXECUTED"
exit 1
fi

Expand Down
6 changes: 4 additions & 2 deletions test_suite/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

cd "$(dirname $0)"

source "tests.source"

# Enable next line to test the garbage collector
Expand Down Expand Up @@ -62,8 +64,8 @@ done
deinit

if [ $FAILED -eq 0 ] ; then
echo "All $EXECUTED test scripts pass."
echo "$0: All $EXECUTED test scripts pass."
else
echo "FAILED: $FAILED / $EXECUTED"
echo "$0: FAILED: $FAILED / $EXECUTED"
exit 1
fi
13 changes: 8 additions & 5 deletions tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@ set -e

JSONNET_BIN="${JSONNET_BIN:-./jsonnet}"
TEST_SNIPPET="std.assertEqual(({ x: 1, y: self.x } { x: 2 }).y, 2)"
echo -n "snippet: "
"$JSONNET_BIN" -e "${TEST_SNIPPET}" || FAIL=TRUE

if [ -z "$DISABLE_LIB_TESTS" ]; then
echo -n 'libjsonnet_test_snippet: '
LD_LIBRARY_PATH=. ./libjsonnet_test_snippet "${TEST_SNIPPET}" || FAIL=TRUE
echo -n 'libjsonnet_test_file: '
LD_LIBRARY_PATH=. ./libjsonnet_test_file "test_suite/object.jsonnet" || FAIL=TRUE
fi
(cd examples ; ./check.sh) || FAIL=TRUE
(cd examples/terraform ; ./check.sh) || FAIL=TRUE
(cd test_suite ; ./run_tests.sh) || FAIL=TRUE
examples/check.sh || FAIL=TRUE
examples/terraform/check.sh || FAIL=TRUE
test_suite/run_tests.sh || FAIL=TRUE
if [ -z "$DISABLE_FMT_TESTS" ]; then
(cd test_suite ; ./run_fmt_tests.sh) || FAIL=TRUE
(cd test_suite ; ./run_fmt_idempotence_tests.sh) || FAIL=TRUE
test_suite/run_fmt_tests.sh || FAIL=TRUE
test_suite/run_fmt_idempotence_tests.sh || FAIL=TRUE
fi
if [ -n "$FAIL" ]; then
echo "TESTS FAILED"
Expand Down