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

Add support for parsing YAML #7340

Open
wants to merge 28 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
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
6 changes: 6 additions & 0 deletions packaging/dependencies.nix
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,12 @@ scope: {
];
});

rapidyaml = pkgs.rapidyaml.overrideAttrs(old: old // {
cmakeFlags = [
"-DRYML_WITH_TAB_TOKENS=ON"
];
});

inherit resolvePath filesetToSource;

mkMesonDerivation =
Expand Down
89 changes: 89 additions & 0 deletions src/libexpr-tests/compose-yaml-test-suite.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#!/bin/bash

testclass="FromYAMLTest"
testmethod="execYAMLTest"

if [ -z "$1" ]; then
echo "Usage: $0 PathToYamlTestSuiteRepository"
echo
echo "This script processes test cases from the yaml-test-suite repository (https://github.com/yaml/yaml-test-suite) and converts them into gtest tests for 'builtins.fromYAML'."
exit 1
fi

echo "/* Generated by $(basename "$0") */"
echo
echo "#pragma once"
echo

for f in "$1"/src/*.yaml; do
testname="$(basename "${f}" .yaml)"
echo "static constexpr std::string_view T_${testname} = R\"RAW("
cat "${f}"
case "${testname}" in
"4ABK")
cat << EOL
json: |
{
"unquoted": "separate",
"http://foo.com": null,
"omitted value": null
}
EOL
;;
# "SM9W")
# echo " # not JSON compatible due to null key"
# echo " fail: true"
# ;;
# "UKK6")
# echo " # empty document"
# echo " fail: true"
# ;;
*)
;;
esac
echo ")RAW\";"
echo
done

echo "namespace {"
echo "using namespace nix;"
echo
for f in "$1"/src/*.yaml; do
testname="$(basename "${f}" .yaml)"
ignore="false"
skip="false"
throw_comment=""
# shellcheck disable=SC2221,SC2222
case "${testname}" in
"H7TQ"|"MUS6"|"ZYU8")
echo "/** This test is ignored because these tests are not required to fail and rapidyaml ignores the YAML version string."
ignore="true"
;;
"3HFZ"|"4EJS"|"5TRB"|"5U3A"|"7LBH"|"9C9N"|"9MQT"|"CVW2"|"CXX2"|"D49Q"|"DK4H"|"DK95"|"G5U8"|"JKF3"|"N782"|"QB6E"|"QLJ7"|"RXY3"|"S4GJ"|"S98Z"|"SY6V"|"VJP3"|"X4QW"|"Y79Y"|"YJV2"|"ZCZ6"|"ZL4Z"|"ZXT5"|"3HFZ"|"4EJS"|"5TRB"|"5U3A"|"7LBH"|"9C9N"|"9MQT"|"CVW2"|"CXX2"|"D49Q"|"DK4H"|"DK95"|"G5U8"|"JKF3"|"N782"|"QB6E"|"QLJ7"|"RXY3"|"S4GJ"|"S98Z"|"SY6V"|"VJP3"|"X4QW"|"Y79Y"|"YJV2"|"ZCZ6"|"ZL4Z"|"ZXT5")
skip="true"
;;
"565N")
throw_comment="nix has no binary data type"
;;
"5TYM"|"6CK3"|"6WLZ"|"7FWL"|"9WXW"|"C4HZ"|"CC74"|"CUP7"|"M5C3"|"P76L"|"UGM3"|"Z67P"|"Z9M4")
throw_comment="usage of unknown tags"
;;
"2XXW"|"J7PZ")
throw_comment="usage of optional tag like !!set and !!omap (not implemented)"
;;
esac
echo "TEST_F(${testclass}, T_${testname})"
echo "{"
if [ -n "${throw_comment}" ]; then
echo " EXPECT_THROW(${testmethod}(T_${testname}), EvalError) << \"${throw_comment}\";"
else
if [ "${skip}" = "true" ]; then
echo " GTEST_SKIP() << \"Reason: Invalid yaml is parsed successfully\";"
fi
echo " ${testmethod}(T_${testname});"
fi
echo "}"
[[ "${ignore}" = "true" ]] && echo "*/"
echo
done
echo "} /* namespace */"
1 change: 1 addition & 0 deletions src/libexpr-tests/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ sources = files(
'value/context.cc',
'value/print.cc',
'value/value.cc',
'yaml.cc'
)

include_dirs = [include_directories('.')]
Expand Down
Loading
Loading