mirror of
https://github.com/valitydev/yamerl.git
synced 2024-11-06 02:45:23 +00:00
Merge branch 'switch-to-rebar3'
This commit is contained in:
commit
875a3d955d
32
.gitignore
vendored
32
.gitignore
vendored
@ -1,36 +1,10 @@
|
||||
.sw?
|
||||
.*.sw?
|
||||
*.beam
|
||||
Makefile.in
|
||||
/ac-aux/
|
||||
/aclocal.m4
|
||||
/autom4te.cache/
|
||||
/config.h.in
|
||||
/config.h.in~
|
||||
/configure
|
||||
|
||||
# Files produced by Debian package.
|
||||
build-stamp
|
||||
configure-stamp
|
||||
debian/*.debhelper.log
|
||||
debian/*.substvars
|
||||
debian/*/
|
||||
debian/build/
|
||||
debian/files
|
||||
!debian/source/
|
||||
|
||||
# Files produced by rebar.
|
||||
/.eunit/
|
||||
/.rebar/
|
||||
/rebar
|
||||
/deps/
|
||||
/test/
|
||||
/ebin/yamerl.app
|
||||
/rebar.lock
|
||||
|
||||
# Elixir Support
|
||||
/_build/
|
||||
/doc/
|
||||
/mix.lock
|
||||
/yamerl-*-contents.tar.gz
|
||||
*.ez
|
||||
/ebin
|
||||
/rebar.lock
|
||||
/rebar3.crashdump
|
||||
|
25
.travis.yml
25
.travis.yml
@ -1,15 +1,20 @@
|
||||
# vim:sw=2:et:
|
||||
|
||||
language: erlang
|
||||
otp_release:
|
||||
- 19.0
|
||||
- 18.0
|
||||
- 17.0
|
||||
- R16B03-1
|
||||
- R16B03
|
||||
- R16B02
|
||||
- R16B01
|
||||
- R15B03
|
||||
- R15B02
|
||||
- R15B01
|
||||
- '19.1'
|
||||
- '18.3'
|
||||
- '17.5'
|
||||
- 'R16B03-1'
|
||||
|
||||
install:
|
||||
- curl -O -L https://s3.amazonaws.com/rebar3/rebar3
|
||||
- chmod +x rebar3
|
||||
- ./rebar3 update
|
||||
|
||||
script:
|
||||
- ./rebar3 eunit
|
||||
- ./rebar3 dialyzer
|
||||
|
||||
notifications:
|
||||
email:
|
||||
|
15
Makefile.am
15
Makefile.am
@ -1,15 +0,0 @@
|
||||
ACLOCAL_FLAGS = -I m4
|
||||
ACLOCAL_AMFLAGS = -I m4
|
||||
|
||||
SUBDIRS = include src ebin testsuite
|
||||
|
||||
EXTRA_DIST = README.md \
|
||||
AUTHORS \
|
||||
COPYING \
|
||||
debian/changelog \
|
||||
debian/compat \
|
||||
debian/control \
|
||||
debian/copyright \
|
||||
debian/rules \
|
||||
debian/source/format \
|
||||
debian/source/options
|
59
README.md
59
README.md
@ -6,45 +6,52 @@ YAML web site](http://www.yaml.org/). You may also want to check the
|
||||
[YAML Wikipedia article](http://en.wikipedia.org/wiki/YAML).
|
||||
|
||||
**yamerl** is a pure [Erlang application](http://www.erlang.org/)
|
||||
which is able to parse [YAML 1.1](http://yaml.org/spec/1.1/) and [YAML
|
||||
1.2](http://www.yaml.org/spec/1.2/spec.html) documents, as well as
|
||||
JSON documents. It only depends on standard Erlang/OTP applications;
|
||||
no external dependency is required. It doesn't use native code either
|
||||
(neither port drivers nor NIFs).
|
||||
which is able to parse [YAML 1.1](http://yaml.org/spec/1.1/) and
|
||||
[YAML 1.2](http://www.yaml.org/spec/1.2/spec.html) documents, as well
|
||||
as [JSON](http://json.org/) documents. It only depends on standard
|
||||
Erlang/OTP applications; no external dependency is required. It doesn't
|
||||
use native code either (neither port drivers nor NIFs).
|
||||
|
||||
yamerl is distributed under the terms of the **2-clause BSD license**;
|
||||
see `COPYING`.
|
||||
|
||||
[![Build Status](https://travis-ci.org/yakaz/yamerl.svg?branch=master)](https://travis-ci.org/yakaz/yamerl)
|
||||
|
||||
## Installation
|
||||
## Integrate to your project
|
||||
|
||||
yamerl uses [Rebar 3](http://www.rebar3.org/) as its build system so
|
||||
it can be integrated to many common build systems.
|
||||
|
||||
### Rebar
|
||||
|
||||
If you use rebar, you can run the following command to build the
|
||||
application:
|
||||
```bash
|
||||
rebar compile
|
||||
yamerl is available as a [Hex.pm package](https://hex.pm/packages/yamerl).
|
||||
Thus you can simply list it as a package dependency in your `rebar.config`:
|
||||
|
||||
```erlang
|
||||
{deps, [yamerl]}.
|
||||
```
|
||||
|
||||
### Autotools
|
||||
### Erlang.mk
|
||||
|
||||
If you use the Autotools and `make(1)`, run the following commands to
|
||||
build the application:
|
||||
```bash
|
||||
# Generate Autotools files.
|
||||
autoreconf -vif
|
||||
Erlang.mk knows about yamerl. You just need to add `yamerl` as a
|
||||
dependency in your `Makefile`:
|
||||
|
||||
# Build the application.
|
||||
./configure
|
||||
make
|
||||
|
||||
# Install it.
|
||||
sudo make install
|
||||
```make
|
||||
DEPS = yamerl
|
||||
```
|
||||
|
||||
The default installation path is your Erlang's distribution libraries
|
||||
directory (see `code:lib_dir()`).
|
||||
### Mix
|
||||
|
||||
yamerl is available as a [Hex.pm package](https://hex.pm/packages/yamerl).
|
||||
Thus you can simply list its name in your `mix.exs`:
|
||||
|
||||
```elixir
|
||||
def project do
|
||||
[
|
||||
deps: [{:yamerl, ">= 0.4.0"}]
|
||||
]
|
||||
end
|
||||
```
|
||||
|
||||
## Getting started
|
||||
|
||||
@ -56,7 +63,7 @@ application:start(yamerl).
|
||||
Now, one can use the `yamerl_constr` module to parse and construct a
|
||||
list of documents from:
|
||||
* an in-memory document (string or binary);
|
||||
* a file;
|
||||
* a regualr file;
|
||||
* a stream.
|
||||
|
||||
Because a YAML input stream may contain multiple documents,
|
||||
@ -205,5 +212,5 @@ yamerl_constr:file("system.yaml", [{detailed_constr, true}]).
|
||||
|
||||
## Complete documentation
|
||||
|
||||
See the `doc` subdirectory for a complete user guide and reference
|
||||
See https://hexdocs.pm/yamerl/ for a complete user guide and reference
|
||||
manual.
|
||||
|
319
configure.ac
319
configure.ac
@ -1,319 +0,0 @@
|
||||
dnl ------------------------------------------------------------------
|
||||
dnl Autoconf initialization.
|
||||
dnl ------------------------------------------------------------------
|
||||
|
||||
AC_INIT([yamerl], [0.3.3])
|
||||
|
||||
AC_CONFIG_SRCDIR([src/yamerl_app.erl])
|
||||
AC_CONFIG_MACRO_DIR([m4])
|
||||
AC_CONFIG_AUX_DIR([ac-aux])
|
||||
|
||||
AM_INIT_AUTOMAKE([1.11 -Wall foreign])
|
||||
|
||||
AC_PREREQ([2.64])
|
||||
|
||||
ECHO=echo
|
||||
COLORED_ECHO_INIT
|
||||
|
||||
dnl ------------------------------------------------------------------
|
||||
dnl Internal functions for this configure script.
|
||||
dnl ------------------------------------------------------------------
|
||||
|
||||
dnl EMKOPTS is used by Emakefile(s).
|
||||
append_to_EMKOPTS () {
|
||||
if test -z "[$]EMKOPTS"; then
|
||||
EMKOPTS="[$]1"
|
||||
else
|
||||
EMKOPTS="[$]{EMKOPTS% }, [$]1"
|
||||
fi
|
||||
}
|
||||
|
||||
dnl Expand shell variables to have a nice output in the final report.
|
||||
expand_var () {
|
||||
local v=`eval echo '$'[$]1`
|
||||
while test "`echo [$]v | grep [[$]] > /dev/null && echo nok`"; do
|
||||
v=`eval echo [$]v`
|
||||
done
|
||||
echo [$]v
|
||||
}
|
||||
|
||||
dnl ------------------------------------------------------------------
|
||||
dnl Options.
|
||||
dnl ------------------------------------------------------------------
|
||||
|
||||
dnl Debugging option.
|
||||
AC_ARG_ENABLE([debug],
|
||||
AC_HELP_STRING([--enable-debug],
|
||||
[turn on debugging [[default=yes]]]),,
|
||||
enable_debug=yes)
|
||||
if test "x${enable_debug}" = "xyes"; then
|
||||
append_to_EMKOPTS "{d, debug}"
|
||||
fi
|
||||
|
||||
AC_ARG_ENABLE([warnings],
|
||||
AC_HELP_STRING([--enable-warnings],
|
||||
[treat warnings as errors [[default=no]]]),,
|
||||
enable_warnings=no)
|
||||
if test "x${enable_warnings}" = "xyes"; then
|
||||
append_to_EMKOPTS "warnings_as_errors"
|
||||
fi
|
||||
|
||||
AC_ARG_ENABLE([export_all],
|
||||
AC_HELP_STRING([--enable-export-all],
|
||||
[export all Erlang functions [[default=no]]]),,
|
||||
enable_export_all=no)
|
||||
if test "x${enable_export_all}" = "xyes"; then
|
||||
append_to_EMKOPTS "export_all"
|
||||
fi
|
||||
|
||||
dnl Include debug symbols.
|
||||
append_to_EMKOPTS "debug_info"
|
||||
|
||||
dnl Print any warnings.
|
||||
append_to_EMKOPTS "report_warnings"
|
||||
append_to_EMKOPTS "{warn_format, 1}"
|
||||
append_to_EMKOPTS "warn_export_vars"
|
||||
append_to_EMKOPTS "warn_shadow_vars"
|
||||
append_to_EMKOPTS "warn_unused_import"
|
||||
|
||||
dnl ------------------------------------------------------------------
|
||||
dnl Erlang environment.
|
||||
dnl ------------------------------------------------------------------
|
||||
|
||||
echo
|
||||
COLORED_ECHO([%BErlang environment%b])
|
||||
|
||||
dnl Available flags.
|
||||
AC_ARG_WITH([erlang],
|
||||
AC_HELP_STRING([--with-erlang=PREFIX],
|
||||
[prefix where Erlang is installed (optional)]),
|
||||
with_erlang=${withval%/},
|
||||
with_erlang="")
|
||||
|
||||
dnl erl(1) is used to compile Erlang modules.
|
||||
if test "x${with_erlang}" = "x"; then
|
||||
AC_ERLANG_PATH_ERL
|
||||
AC_ERLANG_PATH_ERLC
|
||||
else
|
||||
erl_path="${with_erlang}/bin"
|
||||
AC_ERLANG_PATH_ERL(, [$erl_path$PATH_SEPARATOR$PATH])
|
||||
AC_ERLANG_PATH_ERLC(, [$erl_path$PATH_SEPARATOR$PATH])
|
||||
fi
|
||||
|
||||
if test "x${ERL}" = "x"; then
|
||||
AC_MSG_ERROR([
|
||||
Erlang not found. Fill the ERL variable with erl(1) path or provide
|
||||
Erlang prefix with --with-erlang.])
|
||||
fi
|
||||
|
||||
dnl escript(1) is used by the testsuite.
|
||||
AC_ARG_VAR([ESCRIPT], [Erlang/OTP interpreter command [autodetected]])
|
||||
|
||||
if test "x${ESCRIPT}" = "x"; then
|
||||
if test "x${with_erlang}" = "x"; then
|
||||
AC_PATH_PROG([ESCRIPT], [escript],,)
|
||||
else
|
||||
erl_path="${with_erlang}/bin"
|
||||
AC_PATH_PROG([ESCRIPT], [escript],,
|
||||
[$erl_path$PATH_SEPARATOR$PATH])
|
||||
fi
|
||||
else
|
||||
AC_MSG_CHECKING([for escript])
|
||||
AC_MSG_RESULT([$ESCRIPT])
|
||||
fi
|
||||
|
||||
if test "x${ESCRIPT}" = "x"; then
|
||||
AC_MSG_WARN([
|
||||
escript(1) not found. Fill the ESCRIPT variable with escript(1) path if
|
||||
you want to use the testsuite.])
|
||||
fi
|
||||
|
||||
dnl dialyzer(1) is used by the testsuite.
|
||||
AC_ARG_VAR([DIALYZER], [Erlang/OTP discrepancy analyzer [autodetected]])
|
||||
|
||||
if test "x${DIALYZER}" = "x"; then
|
||||
if test "x${with_erlang}" = "x"; then
|
||||
AC_PATH_PROG([DIALYZER], [dialyzer],,)
|
||||
else
|
||||
erl_path="${with_erlang}/bin"
|
||||
AC_PATH_PROG([DIALYZER], [dialyzer],,
|
||||
[$erl_path$PATH_SEPARATOR$PATH])
|
||||
fi
|
||||
else
|
||||
AC_MSG_CHECKING([for dialyzer])
|
||||
AC_MSG_RESULT([$DIALYZER])
|
||||
fi
|
||||
|
||||
if test "x${DIALYZER}" = "x"; then
|
||||
AC_MSG_WARN([
|
||||
dialyzer(1) not found. Fill the DIALYZER variable with dialyzer(1) path if
|
||||
you want it to be run during the testsuite.])
|
||||
fi
|
||||
|
||||
dnl Declare ERL_LIBS as precious.
|
||||
AC_ARG_VAR([ERL_LIBS], [Erlang/OTP applications search path [none]])
|
||||
|
||||
dnl Get Erlang $ROOT dir and lib dir.
|
||||
AC_ERLANG_SUBST_ROOT_DIR
|
||||
AC_ERLANG_SUBST_LIB_DIR
|
||||
|
||||
dnl Get ERTS version.
|
||||
ERLANG_CHECK_ERTS
|
||||
ERLANG_CHECK_RELEASE
|
||||
|
||||
dnl Erlang R14B02 (ERTS 5.8.3) is required.
|
||||
AX_COMPARE_VERSION([${ERLANG_ERTS_VER}], [ge], [5.8.3],
|
||||
[is_erlang_r14b02="yes"],
|
||||
[is_erlang_r14b02="no"])
|
||||
if test "x${is_erlang_r14b02}" = "xno"; then
|
||||
AC_MSG_ERROR([
|
||||
Erlang R14B02 is required but only Erlang $ERLANG_RELEASE was found!])
|
||||
fi
|
||||
|
||||
dnl Determine directories for installation.
|
||||
if test "x${prefix}" = "xNONE"; then
|
||||
dnl Inside Erlang lib directory.
|
||||
ERLANG_INSTALL_LIB_DIR="${ERLANG_LIB_DIR}"
|
||||
else
|
||||
dnl Under $prefix
|
||||
ERLANG_INSTALL_LIB_DIR="${prefix}"
|
||||
fi
|
||||
|
||||
AC_ERLANG_SUBST_INSTALL_LIB_DIR
|
||||
AC_ERLANG_SUBST_INSTALL_LIB_SUBDIR(AC_PACKAGE_NAME, AC_PACKAGE_VERSION)
|
||||
|
||||
dnl ------------------------------------------------------------------
|
||||
dnl Erlang applicatons.
|
||||
dnl ------------------------------------------------------------------
|
||||
|
||||
dnl "compiler" install directory.
|
||||
AC_ARG_WITH([erlang_compiler],
|
||||
AC_HELP_STRING([--with-erlang-compiler=PREFIX],
|
||||
[prefix where the "compiler" Erlang application is installed (optional)]),
|
||||
with_erlang_compiler=${withval%/},
|
||||
with_erlang_compiler="")
|
||||
|
||||
ERL_LIBS_save=$ERL_LIBS
|
||||
if test "x${with_erlang_compiler}" != "x"; then
|
||||
ERL_LIBS="${with_erlang_compiler}:${ERL_LIBS}"
|
||||
fi
|
||||
export ERL_LIBS
|
||||
AC_ERLANG_CHECK_LIB([compiler],, [AC_MSG_ERROR([
|
||||
"compiler" Erlang application not found.
|
||||
|
||||
Provide compiler install path with --with-erlang-compiler.])])
|
||||
ERL_LIBS=$ERL_LIBS_save
|
||||
export ERL_LIBS
|
||||
|
||||
dnl "tools" install directory.
|
||||
AC_ARG_WITH([erlang_tools],
|
||||
AC_HELP_STRING([--with-erlang-tools=PREFIX],
|
||||
[prefix where the "tools" Erlang application is installed (optional)]),
|
||||
with_erlang_tools=${withval%/},
|
||||
with_erlang_tools="")
|
||||
|
||||
ERL_LIBS_save=$ERL_LIBS
|
||||
if test "x${with_erlang_tools}" != "x"; then
|
||||
ERL_LIBS="${with_erlang_tools}:${ERL_LIBS}"
|
||||
fi
|
||||
export ERL_LIBS
|
||||
AC_ERLANG_CHECK_LIB([tools],, [AC_MSG_ERROR([
|
||||
"tools" Erlang application not found.
|
||||
|
||||
Provide tools install path with --with-erlang-tools.])])
|
||||
ERL_LIBS=$ERL_LIBS_save
|
||||
export ERL_LIBS
|
||||
|
||||
dnl "eunit" install directory.
|
||||
AC_ARG_WITH([erlang_eunit],
|
||||
AC_HELP_STRING([--with-erlang-eunit=PREFIX],
|
||||
[prefix where the "eunit" Erlang application is installed (optional)]),
|
||||
with_erlang_eunit=${withval%/},
|
||||
with_erlang_eunit="")
|
||||
|
||||
ERL_LIBS_save=$ERL_LIBS
|
||||
if test "x${with_erlang_eunit}" != "x"; then
|
||||
ERL_LIBS="${with_erlang_eunit}:${ERL_LIBS}"
|
||||
fi
|
||||
export ERL_LIBS
|
||||
AC_ERLANG_CHECK_LIB([eunit],, [AC_MSG_WARN([
|
||||
"eunit" Erlang application not found.
|
||||
|
||||
Provide eunit install path with --with-erlang-eunit.])])
|
||||
ERL_LIBS=$ERL_LIBS_save
|
||||
export ERL_LIBS
|
||||
|
||||
dnl "yamler" install directory.
|
||||
AC_ARG_WITH([erlang_yamler],
|
||||
AC_HELP_STRING([--with-erlang-yamler=PREFIX],
|
||||
[prefix where the "yamler" Erlang application is installed (optional)]),
|
||||
with_erlang_yamler=${withval%/},
|
||||
with_erlang_yamler="")
|
||||
|
||||
ERL_LIBS_save=$ERL_LIBS
|
||||
if test "x${with_erlang_yamler}" != "x"; then
|
||||
ERL_LIBS="${with_erlang_yamler}:${ERL_LIBS}"
|
||||
fi
|
||||
export ERL_LIBS
|
||||
AC_ERLANG_CHECK_LIB([yamler])
|
||||
ERL_LIBS=$ERL_LIBS_save
|
||||
export ERL_LIBS
|
||||
|
||||
AM_CONDITIONAL([HAVE_YAMLER], [test x"$ERLANG_LIB_DIR_yamler" != x"not found"])
|
||||
|
||||
dnl ------------------------------------------------------------------
|
||||
dnl Final substitutions.
|
||||
dnl ------------------------------------------------------------------
|
||||
|
||||
AC_SUBST(EMKOPTS)
|
||||
|
||||
AC_SUBST(APP_RELEASE_DATE)
|
||||
AC_SUBST(APP_DISTSUFFIX)
|
||||
|
||||
exp_ERLANG_INSTALL_LIB_DIR_yamerl=`expand_var ERLANG_INSTALL_LIB_DIR_yamerl`
|
||||
AC_SUBST(exp_ERLANG_INSTALL_LIB_DIR_yamerl)
|
||||
|
||||
dnl ------------------------------------------------------------------
|
||||
dnl Autoconf output.
|
||||
dnl ------------------------------------------------------------------
|
||||
|
||||
echo
|
||||
AM_CONFIG_HEADER([config.h])
|
||||
AC_CONFIG_FILES([
|
||||
include/Makefile
|
||||
src/Makefile
|
||||
src/Emakefile.in
|
||||
ebin/Makefile
|
||||
ebin/yamerl.app.in
|
||||
ebin/yamerl.appup
|
||||
testsuite/Makefile
|
||||
testsuite/etest
|
||||
Makefile
|
||||
])
|
||||
AC_CONFIG_FILES([
|
||||
testsuite/dialyzer
|
||||
], [chmod +x testsuite/dialyzer])
|
||||
AC_CONFIG_FILES([
|
||||
testsuite/benchmark
|
||||
], [chmod +x testsuite/benchmark])
|
||||
AC_OUTPUT
|
||||
|
||||
dnl --------------------------------------------------
|
||||
dnl Configuration report
|
||||
dnl --------------------------------------------------
|
||||
|
||||
echo
|
||||
COLORED_ECHO([ %B== ${PACKAGE_NAME} ${PACKAGE_VERSION}${APP_DISTSUFFIX} ==%b])
|
||||
echo
|
||||
COLORED_ECHO([Configuration:])
|
||||
COLORED_ECHO([ Prefix: ${prefix}])
|
||||
COLORED_ECHO([ Application dir.: ${exp_ERLANG_INSTALL_LIB_DIR_yamerl}])
|
||||
echo
|
||||
COLORED_ECHO([ Erlang emulator: ${ERL}])
|
||||
COLORED_ECHO([ Erlang compiler: ${ERLC}])
|
||||
COLORED_ECHO([ Erlang interpreter: ${ESCRIPT}])
|
||||
echo
|
||||
COLORED_ECHO([ Debug: ${enable_debug}])
|
||||
COLORED_ECHO([ Warnings as errors: ${enable_warnings}])
|
||||
COLORED_ECHO([ Export all: ${enable_export_all}])
|
||||
echo
|
49
debian/changelog
vendored
49
debian/changelog
vendored
@ -1,49 +0,0 @@
|
||||
erlang-yamerl (0.3.3-1) stable; urgency=low
|
||||
|
||||
* yamerl_parser: Fix an infinite loop with "key:"
|
||||
|
||||
-- Jean-Sébastien Pédron <jean-sebastien.pedron@dumbbell.fr> Sun, 30 Oct 2016 00:38:26 +0200
|
||||
|
||||
erlang-yamerl (0.3.2-1) stable; urgency=low
|
||||
|
||||
* yamerl_parser: Don't build with HiPE by default
|
||||
* Elixir/hex.pm support
|
||||
* Fix generation of yamerl.app with nawk(1)
|
||||
|
||||
-- Jean-Sébastien Pédron <jean-sebastien.pedron@dumbbell.fr> Sat, 28 Mar 2015 01:43:31 +0100
|
||||
|
||||
erlang-yamerl (0.3.1-1) stable; urgency=low
|
||||
|
||||
* Fix bug with re:run/3 usage and Unicode string (#5).
|
||||
* yamerl_constr: Ensure the node module is loaded.
|
||||
* Allow to run the testsuite using rebar.
|
||||
* Improve documentation.
|
||||
|
||||
-- Jean-Sébastien Pédron <jean-sebastien@yakaz.com> Tue, 22 Jul 2014 16:52:57 +0200
|
||||
|
||||
erlang-yamerl (0.3.0-1) stable; urgency=low
|
||||
|
||||
* Rename application to "yamerl".
|
||||
* Fix Debian package.
|
||||
|
||||
-- Jean-Sébastien Pédron <jean-sebastien@yakaz.com> Wed, 26 Mar 2014 11:08:22 +0100
|
||||
|
||||
erlang-yaml (0.2.0-1) experimental; urgency=low
|
||||
|
||||
* Package for Erlang R15B03.
|
||||
|
||||
-- Jean-Sébastien Pédron <jean-sebastien@yakaz.com> Tue, 11 Sep 2012 15:22:24 +0200
|
||||
|
||||
erlang-yaml (0.1.1-1) experimental; urgency=low
|
||||
|
||||
* Add float support
|
||||
* Add YAML failsafe/json/core schemas
|
||||
* Bugfixes
|
||||
|
||||
-- Jean-Sébastien Pédron <jean-sebastien@yakaz.com> Fri, 27 Jan 2012 10:33:02 +0100
|
||||
|
||||
erlang-yaml (0.1.0-1) experimental; urgency=low
|
||||
|
||||
* Initial release.
|
||||
|
||||
-- Jean-Sébastien Pédron <jean-sebastien@yakaz.com> Thu, 23 Jun 2011 17:56:47 +0200
|
1
debian/compat
vendored
1
debian/compat
vendored
@ -1 +0,0 @@
|
||||
9
|
30
debian/control
vendored
30
debian/control
vendored
@ -1,30 +0,0 @@
|
||||
Source: erlang-yamerl
|
||||
Section: devel
|
||||
Priority: optional
|
||||
Maintainer: Jean-Sébastien Pédron <jean-sebastien.pedron@dumbbell.fr>
|
||||
Uploaders: Christopher Faulet <christopher@yakaz.com>,
|
||||
Jean-Sébastien Pédron <jean-sebastien@yakaz.com>
|
||||
Build-Depends: debhelper (>= 9),
|
||||
dh-autoreconf,
|
||||
erlang-base-hipe | erlang-base,
|
||||
erlang-tools,
|
||||
erlang-eunit,
|
||||
erlang-xmerl,
|
||||
erlang-dev
|
||||
Standards-Version: 3.9.4
|
||||
|
||||
Package: erlang-yamerl
|
||||
Architecture: all
|
||||
Depends: ${misc:Depends}, ${erlang:Depends}
|
||||
Description: Pure Erlang YAML 1.2 parser
|
||||
YAML is a human-friendly, cross language, Unicode based data
|
||||
serialization language designed around the common native data types of
|
||||
agile programming languages
|
||||
.
|
||||
yamerl is a pure Erlang application which is able to parse YAML 1.1
|
||||
and YAML 1.2 documents, as well as JSON documents. It only depends on
|
||||
standard Erlang/OTP applications, no external dependency is required.
|
||||
It doesn't use native code either (neither port drivers nor NIFs)
|
||||
.
|
||||
yamerl is distributed under the terms of the 2-clause BSD license; see
|
||||
COPYING.
|
59
debian/copyright
vendored
59
debian/copyright
vendored
@ -1,59 +0,0 @@
|
||||
Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
|
||||
Upstream-Name: yamerl
|
||||
Upstream-Contact: Jean-Sébastien Pédron <jean-sebastien.pedron@dumbbell.fr>
|
||||
Source: https://github.com/yakaz/yamerl
|
||||
|
||||
Files: *
|
||||
Copyright: 2012-2014, Yakaz
|
||||
2016, Jean-Sébastien Pédron <jean-sebastien.pedron@dumbbell.fr>
|
||||
License: BSD-2-clause
|
||||
Copyright (c) 2012-2014 Yakaz
|
||||
Copyright (c) 2016 Jean-Sébastien Pédron <jean-sebastien.pedron@dumbbell.fr>
|
||||
All rights reserved.
|
||||
.
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
.
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGE.
|
||||
|
||||
Files: testsuite/data/benchmark/mochijson2.erl
|
||||
Copyright: 2007, Mochi Media, Inc.
|
||||
License: Expat
|
||||
This is the MIT license.
|
||||
.
|
||||
Copyright (c) 2007 Mochi Media, Inc.
|
||||
.
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
.
|
||||
The above copyright notice and this permission notice shall be included
|
||||
in all copies or substantial portions of the Software.
|
||||
.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
11
debian/rules
vendored
11
debian/rules
vendored
@ -1,11 +0,0 @@
|
||||
#!/usr/bin/make -f
|
||||
# -*- makefile -*-
|
||||
|
||||
# Uncomment this to turn on verbose mode.
|
||||
#export DH_VERBOSE=1
|
||||
|
||||
%:
|
||||
dh $@ --parallel --with autoreconf
|
||||
|
||||
override_dh_auto_configure:
|
||||
dh_auto_configure -- --prefix=/usr/lib/erlang/lib
|
1
debian/source/format
vendored
1
debian/source/format
vendored
@ -1 +0,0 @@
|
||||
3.0 (quilt)
|
31
debian/source/options
vendored
31
debian/source/options
vendored
@ -1,31 +0,0 @@
|
||||
tar-ignore = *.a
|
||||
tar-ignore = *.la
|
||||
tar-ignore = *.o
|
||||
tar-ignore = *.so
|
||||
tar-ignore = .*.sw?
|
||||
tar-ignore = */*~
|
||||
tar-ignore = ,,*
|
||||
tar-ignore = .[#~]*
|
||||
tar-ignore = .arch-ids
|
||||
tar-ignore = .arch-inventory
|
||||
tar-ignore = .be
|
||||
tar-ignore = .bzr
|
||||
tar-ignore = .bzr.backup
|
||||
tar-ignore = .bzr.tags
|
||||
tar-ignore = .bzrignore
|
||||
tar-ignore = .cvsignore
|
||||
tar-ignore = .deps
|
||||
tar-ignore = .git
|
||||
tar-ignore = .gitattributes
|
||||
tar-ignore = .gitignore
|
||||
tar-ignore = .hg
|
||||
tar-ignore = .hgignore
|
||||
tar-ignore = .hgtags
|
||||
tar-ignore = .shelf
|
||||
tar-ignore = .svn
|
||||
tar-ignore = CVS
|
||||
tar-ignore = DEADJOE
|
||||
tar-ignore = RCS
|
||||
tar-ignore = _MTN
|
||||
tar-ignore = _darcs
|
||||
tar-ignore = {arch}
|
@ -1,7 +0,0 @@
|
||||
# yamerl Documentation
|
||||
|
||||
* [Features](features.md#yamerl-features)
|
||||
* [Installation instructions](installation.md#yamerl-installation)
|
||||
* [Reference Manual](reference-manual#yamerl-reference-manual)
|
||||
* [User Guide](user-guide#yamerl-user-guide)
|
||||
* [Alternatives to yamerl](alternatives.md#alternatives-to-yamerl)
|
@ -1,15 +0,0 @@
|
||||
# Alternatives to yamerl
|
||||
|
||||
## YAML parsers
|
||||
|
||||
* [yamler](https://github.com/goertzenator/yamler):
|
||||
* Based on libyaml, wrapped in a NIF
|
||||
* Support YAML 1.1
|
||||
* Faster than yamerl
|
||||
* Support Erlang atoms, however, single-quoted scalar are treated as atom, which breaks the YAML specifications
|
||||
* Don't support Erlang fun()
|
||||
|
||||
## JSON parsers
|
||||
|
||||
* `mochijson2`, provided by [Mochiweb](https://github.com/mochi/mochiweb):
|
||||
* A lot faster than yamerl
|
@ -1,77 +0,0 @@
|
||||
# Features
|
||||
|
||||
## When to use or not yamerl
|
||||
|
||||
### Advantages
|
||||
|
||||
* Pure Erlang implementation:
|
||||
* should scale more easily than a port-driver based implementation;
|
||||
* won't take the whole VM down in case of a crash.
|
||||
* YAML 1.2 support, which is not widely supported in many other languages.
|
||||
|
||||
### Caveats
|
||||
|
||||
* Current implementation is slow, compared to yamler (NIF-based) or any JSON-only parsers.
|
||||
* Adding schemas is not easy.
|
||||
* No support for YAML serialization.
|
||||
|
||||
## Features + examples
|
||||
|
||||
* Support [YAML 1.2](http://www.yaml.org/spec/1.2/spec.html) parsing:
|
||||
|
||||
```erlang
|
||||
yamerl_constr:string("YAML snippet").
|
||||
```
|
||||
|
||||
* Support [YAML 1.1](http://yaml.org/spec/1.1/) parsing:
|
||||
|
||||
```erlang
|
||||
yamerl_constr:string("YAML snippet", [{schema, yaml11}]).
|
||||
```
|
||||
|
||||
* Support [JSON](http://json.org/) parsing:
|
||||
|
||||
```erlang
|
||||
yamerl_constr:string(<<"JSON snippet">>, [{schema, json}]).
|
||||
```
|
||||
|
||||
* Support **Erlang atom** node type, either when tagged as atom, or if autodetected in plain scalars, and, if asked, only if the atom already exists:
|
||||
|
||||
```erlang
|
||||
% Enable support for Erlang atoms.
|
||||
yamerl_app:set_param(node_mods, [yamerl_node_erlang_atom]),
|
||||
yamerl_constr:string("!<tag:yamerl,2012:atom> atom").
|
||||
|
||||
% Autodetect Erlang atoms in plain scalars.
|
||||
yamerl_app:set_param(node_mods, [yamerl_node_erlang_atom]),
|
||||
yamerl_constr:string("atom", [{erlang_atom_autodetection, true}]).
|
||||
|
||||
% Atoms must already exist.
|
||||
yamerl_app:set_param(node_mods, [yamerl_node_erlang_atom]),
|
||||
yamerl_constr:string("atom", [
|
||||
{erlang_atom_autodetection, true},
|
||||
{erlang_atom_only_if_exist, true}
|
||||
]).
|
||||
```
|
||||
|
||||
* Support **Erlang fun()** node type:
|
||||
|
||||
```erlang
|
||||
% Enable support for Erlang fun().
|
||||
yamerl_app:set_param(node_mods, [yamerl_node_erlang_fun]),
|
||||
[Plus_One_Fun] = yamerl_constr:string(<<"!<tag:yamerl,2012:fun> fun(X) -> X + 1 end.">>),
|
||||
|
||||
Plus_One_Fun(2). % Return 3.
|
||||
```
|
||||
|
||||
* Provide a **yamler compatibility layer**:
|
||||
|
||||
```erlang
|
||||
% Both calls return the same value.
|
||||
yaml:load_file("input.yaml", [{schema, yaml_schema_failsafe}]),
|
||||
yamerl_yamler_compat:load_file("input.yaml", [{schema, yaml_schema_failsafe}])
|
||||
```
|
||||
|
||||
## Alternatives to yamerl
|
||||
|
||||
If yamerl doesn't fit your needs, you can read a [list of alternatives](alternatives.md#alternatives-to-yamerl).
|
@ -1,176 +0,0 @@
|
||||
# Installation
|
||||
|
||||
## tl;dr
|
||||
|
||||
### Using Rebar
|
||||
|
||||
1. Take the sources from GitHub and run rebar(1):
|
||||
|
||||
```bash
|
||||
git clone 'https://github.com/yakaz/yamerl.git'
|
||||
cd yamerl/
|
||||
rebar compile
|
||||
```
|
||||
|
||||
### Using the Autotools
|
||||
|
||||
1. Take the sources from GitHub and generate Autotools files:
|
||||
|
||||
```bash
|
||||
git clone 'https://github.com/yakaz/yamerl.git'
|
||||
cd yamerl/
|
||||
autoreconf -vif
|
||||
```
|
||||
|
||||
2. Enter the sources directory and run the usual configure/make/make
|
||||
install:
|
||||
|
||||
```bash
|
||||
./configure
|
||||
make
|
||||
make install
|
||||
```
|
||||
|
||||
The default installation path is your Erlang's distribution libraries
|
||||
directory.
|
||||
|
||||
## Requirements
|
||||
|
||||
### Build dependencies
|
||||
|
||||
If you're using Rebar:
|
||||
* rebar
|
||||
* awk (tested with FreeBSD's awk, mawk and gawk, should work with any
|
||||
flavor of Awk)
|
||||
* Erlang/OTP R14B02 or later
|
||||
|
||||
If you're using the Autotools:
|
||||
* autoconf 2.64 or later
|
||||
* automake 1.11 or later
|
||||
* awk (tested with FreeBSD's awk, mawk and gawk, should work with any
|
||||
flavor of Awk)
|
||||
* make (tested with FreeBSD's make and GNU make, should work with any
|
||||
flavor of make)
|
||||
* Erlang/OTP R14B02 or later
|
||||
|
||||
### Testsuite dependencies
|
||||
|
||||
* Erlang/OTP R14B02 or later
|
||||
* Perl
|
||||
* [yamler](https://github.com/goertzenator/yamler) (optional)
|
||||
|
||||
### Runtime dependencies
|
||||
|
||||
* Erlang/OTP R14B02 or later
|
||||
|
||||
## Building using Rebar
|
||||
|
||||
A single step is required here:
|
||||
```bash
|
||||
rebar compile
|
||||
```
|
||||
|
||||
If you want to run the testsuite:
|
||||
```bash
|
||||
rebar eunit
|
||||
```
|
||||
|
||||
## Building using the Autotools
|
||||
|
||||
### Generating the Autotools files
|
||||
|
||||
> If you use a release tarball, you can skip this step.
|
||||
|
||||
You need to generate the Autotools files:
|
||||
* after a fresh clone of the Git repository;
|
||||
* each time you modify `configure.ac` or any `Makefile.am`
|
||||
|
||||
```bash
|
||||
autoreconf -vif
|
||||
```
|
||||
|
||||
### Configuring the build
|
||||
|
||||
#### Inside sources vs. outside sources
|
||||
|
||||
* The simplest method is to run the `configure` script from the sources
|
||||
directory:
|
||||
|
||||
```bash
|
||||
./configure
|
||||
```
|
||||
|
||||
* The **recommended method** is to run the `configure` script from a
|
||||
separate directory, in order to keep the sources directory clean:
|
||||
|
||||
```bash
|
||||
# Create and enter a separate directory.
|
||||
mkdir build-yamerl
|
||||
cd build-yamerl
|
||||
|
||||
# Execute the configure script from this directory; all files are
|
||||
# created in this directory, not in the sources directory.
|
||||
/path/to/yamerl-sources/configure
|
||||
```
|
||||
|
||||
#### Changing the install path
|
||||
|
||||
The default installation path is your Erlang's distribution libraries
|
||||
directory, as reported by `code:lib_dir()`. To install in a different
|
||||
directory (eg. because you do not have sufficient privileges), you can
|
||||
use the `--prefix` option:
|
||||
```bash
|
||||
.../configure --prefix=$HOME/my-erlang-apps
|
||||
```
|
||||
|
||||
#### Using a non-default Erlang distribution
|
||||
|
||||
By default, the system Erlang distribution is used by querying `erl(1)`
|
||||
taken from the `$PATH`. You can specify another Erlang distribution:
|
||||
|
||||
* using the `--with-erlang` option to point to the Erlang root directory:
|
||||
|
||||
```bash
|
||||
.../configure --with-erlang=/erlang/root/directory
|
||||
```
|
||||
|
||||
* using the `$ERL` variable to point to the alternate `erl(1)` binary:
|
||||
|
||||
```bash
|
||||
.../configure ERL=/path/to/erl
|
||||
```
|
||||
|
||||
### Compiling
|
||||
|
||||
Easy peasy Japanesey!
|
||||
```bash
|
||||
make
|
||||
```
|
||||
|
||||
You can use multiple make jobs (ie. using the `-j` option). However
|
||||
Erlang modules are built using Erlang's `make` application. And, as of
|
||||
this writing (Erlang R15B03), this application doesn't build modules in
|
||||
parallel.
|
||||
|
||||
If you want to run the testsuite:
|
||||
```bash
|
||||
make check
|
||||
```
|
||||
|
||||
## Installing
|
||||
|
||||
> Installation is only supported when using the Autotools.
|
||||
|
||||
* Simply run:
|
||||
|
||||
```bash
|
||||
make install
|
||||
```
|
||||
|
||||
Note that you may need increased privileges.
|
||||
|
||||
* To help mostly packagers, the `$DESTDIR` variable is honored:
|
||||
|
||||
```bash
|
||||
make install DESTDIR=/path/to/fake/root
|
||||
```
|
@ -1,5 +0,0 @@
|
||||
# yamerl Reference Manual
|
||||
|
||||
## Modules
|
||||
|
||||
* [`yamerl_constr`](module-yamerl_constr.md)
|
@ -1,274 +0,0 @@
|
||||
# Module: yamerl\_constr
|
||||
|
||||
## Functions list
|
||||
|
||||
* In-memory string parsing:
|
||||
* [`string/1`](#function-stringstring)
|
||||
* [`string/2`](#function-stringstring-options)
|
||||
* File parsing:
|
||||
* [`file/1`](#function-filefilename)
|
||||
* [`file/2`](#function-filefilename-options)
|
||||
* Stream parsing:
|
||||
* [`new/1`](#function-newsource)
|
||||
* [`new/2`](#function-newsource-options)
|
||||
* [`next_chunk/2`](#function-next_chunkconstr_state-chunk)
|
||||
* [`next_chunk/3`](#function-next_chunkconstr_state-chunk-last_chunk)
|
||||
* [`last_chunk/2`](#function-last_chunkconstr_state-chunk)
|
||||
|
||||
## Functions reference
|
||||
|
||||
### Function: new(Source)
|
||||
|
||||
Same as:
|
||||
```erlang
|
||||
yamerl_constr:new(Source, []).
|
||||
```
|
||||
|
||||
> See [`new/2`](#function-newsource-options).
|
||||
|
||||
### Function: new(Source, Options)
|
||||
|
||||
#### Arguments
|
||||
|
||||
* `Source`: An arbitrary term describing the source of the data.
|
||||
* `Options`: A proplist of options:
|
||||
* `{detailed_constr, boolean()}`: Flag to enable/disable the detailed construction mode (default: `false`).
|
||||
* `{schema, failsafe | json | core | yaml11}`: Name of the official schema to use (default: `core`).
|
||||
* `{node_mods, Mods_List}`: List of Erlang modules to extend supported node types (default: `[]`).
|
||||
|
||||
#### Description
|
||||
|
||||
Create a new construction state.
|
||||
|
||||
The returned state is then used in the [next\_chunk/2](#function-next_chunkconstr_state-chunk), [next\_chunk/3](#function-next_chunkconstr_state-chunk-last_chunk) and [last\_chunk/2](#function-last_chunkconstr_state-chunk) functions.
|
||||
|
||||
#### Return values & exceptions
|
||||
|
||||
If specified options are valid, return a new construction state.
|
||||
|
||||
If specified options are invalid, throw an exception.
|
||||
|
||||
### Function: next\_chunk(Constr\_State, Chunk)
|
||||
|
||||
Same as:
|
||||
```erlang
|
||||
yamerl_constr:next_chunk(Constr_State, Chunk, false).
|
||||
```
|
||||
|
||||
> See [`next_chunk/3`](#function-next_chunkconstr_state-chunk-last_chunk).
|
||||
|
||||
### Function: next\_chunk(Constr\_State, Chunk, Last\_Chunk)
|
||||
|
||||
#### Arguments
|
||||
|
||||
* `Constr_State`: A construction state as returned by [new/1](#function-newsource), [new/2](#function-newsource-options), [next\_chunk/2](#function-next_chunkconstr_state-chunk) or [next\_chunk/3](#function-next_chunkconstr_state-chunk-last_chunk).
|
||||
* `Chunk`: A UTF-8/16/32-encoded binary chunk of a stream containing one or more YAML documents.
|
||||
* `Last_Chunk`: Flag indicating if the given chunk is the last one or not.
|
||||
|
||||
#### Description
|
||||
|
||||
Parse the given chunk and return a new construction state or, if last chunk, a list of constructed YAML documents.
|
||||
|
||||
The chunk must be an Erlang binary, using the UTF-8, UTF-16 or UTF-32 Unicode encoding. A leading _BOM_ character in the first chunk is used to determine the encoding and endianness. If no BOM is present, UTF-8 is assumed.
|
||||
|
||||
#### Return values & exceptions
|
||||
|
||||
If parsing succeeds and `Last_Chunk` is `false`, return `{continue, New_Constr_State}`. The `New_Constr_State` must be used for subsequent calls to [next\_chunk/2](#function-next_chunkconstr_state-chunk), [next\_chunk/3](#function-next_chunkconstr_state-chunk-last_chunk) or [last\_chunk/2](#function-last_chunkconstr_state-chunk).
|
||||
|
||||
If parsing and construction succeed and `Last_Chunk` is `true`, return a list of documents:
|
||||
* Basic-terms-based documents are returned if option `{detailed_constr, false}` is set (default);
|
||||
* Detailed records-based documents are returned if option `{detailed_constr, true}` is set.
|
||||
|
||||
If parsing or construction fails, throw an exception.
|
||||
|
||||
#### Examples
|
||||
|
||||
##### Parse a valid stream
|
||||
|
||||
```erlang
|
||||
Stream_St1 = yamerl_constr:new({file, "<stdin>"}),
|
||||
{continue, Stream_St2} = yamerl_constr:next_chunk(Stream_St1, <<"He">>),
|
||||
{continue, Stream_St3} = yamerl_constr:next_chunk(Stream_St2, <<"ll">>),
|
||||
yamerl_constr:last_chunk(Stream_St3, <<"o!">>).
|
||||
```
|
||||
|
||||
Returns:
|
||||
```erlang
|
||||
% List of documents; here, only one.
|
||||
[
|
||||
% Document root node: a string.
|
||||
"Hello!"
|
||||
].
|
||||
```
|
||||
|
||||
##### Parse an invalid stream
|
||||
|
||||
```erlang
|
||||
Stream_St1 = yamerl_constr:new({file, "<stdin>"}),
|
||||
{continue, Stream_St2} = yamerl_constr:next_chunk(Stream_St1, <<"'He">>),
|
||||
{continue, Stream_St3} = yamerl_constr:next_chunk(Stream_St2, <<"ll">>),
|
||||
yamerl_constr:last_chunk(Stream_St3, <<"o!">>) % Unfinished single-quoted scalar.
|
||||
```
|
||||
|
||||
Throws:
|
||||
```erlang
|
||||
{yamerl_exception,
|
||||
% List of warnings and errors; here, one fatal error.
|
||||
[
|
||||
% Error #1.
|
||||
{yamerl_parsing_error, error,
|
||||
"Unexpected end-of-stream while parsing flow scalar", % Human-readable message.
|
||||
1, 8, % Error location.
|
||||
unexpected_eos,
|
||||
{yamerl_scalar, 1, 1, {yamerl_tag, 1, 1, {non_specific, "!"}}, % Token being parsed.
|
||||
flow, single_quoted,
|
||||
"Hello!"},
|
||||
[]
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
### Function: last\_chunk(Constr\_State, Chunk)
|
||||
|
||||
Same as:
|
||||
```erlang
|
||||
yamerl_constr:next_chunk(Constr_State, Chunk, true).
|
||||
```
|
||||
|
||||
> See [`next_chunk/3`](#function-next_chunkconstr_state-chunk-last_chunk).
|
||||
|
||||
### Function: string(String)
|
||||
|
||||
#### Description
|
||||
|
||||
Same as:
|
||||
```erlang
|
||||
yamerl_constr:string(String, []).
|
||||
```
|
||||
|
||||
> See [`string/2`](#function-stringstring-options).
|
||||
|
||||
### Function: string(String, Options)
|
||||
|
||||
#### Arguments
|
||||
|
||||
* `String`: A string or UTF-8/16/32-encoded binary containing one or more YAML documents.
|
||||
* `Options`: A proplist of options; see [`new/2`](#function-newsource-options).
|
||||
|
||||
#### Description
|
||||
|
||||
Parse the given string and return a list of constructed YAML documents.
|
||||
|
||||
The `String` argument can be:
|
||||
|
||||
* an Erlang string (ie. list):
|
||||
|
||||
```erlang
|
||||
yamerl_constr:string("This is a string").
|
||||
```
|
||||
|
||||
* a binary using the UTF-8, UTF-16 or UTF-32 Unicode encoding. A leading _BOM_ character is used to determine the encoding and endianness. If no BOM is present, UTF-8 is assumed.
|
||||
|
||||
```erlang
|
||||
yamerl_constr:string(<<50,32,226,130,172>>). % The string "2 €" encoded in UTF-8.
|
||||
```
|
||||
|
||||
#### Return values & exceptions
|
||||
|
||||
If parsing and construction succeed, return a list of documents:
|
||||
* Basic-terms-based documents are returned if option `{detailed_constr, false}` is set (default);
|
||||
* Detailed records-based documents are returned if option `{detailed_constr, true}` is set.
|
||||
|
||||
If parsing or construction fails, throw an exception.
|
||||
|
||||
#### Examples
|
||||
|
||||
##### Get simple documents
|
||||
|
||||
```erlang
|
||||
yamerl_constr:string("Hello!").
|
||||
```
|
||||
|
||||
Returns:
|
||||
```erlang
|
||||
% List of documents; here, only one.
|
||||
[
|
||||
% Document root node: a string.
|
||||
"Hello!"
|
||||
].
|
||||
```
|
||||
|
||||
##### Get detailed documents
|
||||
|
||||
```erlang
|
||||
yamerl_constr:string("Hello!", [detailed_constr]).
|
||||
```
|
||||
|
||||
Returns:
|
||||
```erlang
|
||||
% List of documents; here, only one.
|
||||
[
|
||||
% Document #1.
|
||||
{yamerl_doc,
|
||||
% Document root node: a string.
|
||||
{yamerl_str, yamerl_node_str, "tag:yaml.org,2002:str",
|
||||
[{line, 1}, {column, 1}], % Node location in the original string.
|
||||
"Hello!" % String value.
|
||||
}
|
||||
}
|
||||
].
|
||||
```
|
||||
|
||||
##### Parse an invalid document
|
||||
|
||||
```erlang
|
||||
yamerl_constr:string(<<"'Oh-oh...">>). % Unfinished single-quoted scalar.
|
||||
```
|
||||
|
||||
Throws an exception:
|
||||
```erlang
|
||||
{yamerl_exception,
|
||||
% List of warnings and errors; here, one fatal error.
|
||||
[
|
||||
% Error #1.
|
||||
{yamerl_parsing_error, error,
|
||||
"Unexpected end-of-stream while parsing flow scalar", % Human-readable message.
|
||||
1, 10, % Error location.
|
||||
unexpected_eos,
|
||||
{yamerl_scalar, 1, 1, {yamerl_tag, 1, 1, {non_specific, "!"}}, % Token being parsed.
|
||||
flow, single_quoted,
|
||||
"Oh-oh..."},
|
||||
[]
|
||||
}
|
||||
]
|
||||
}.
|
||||
```
|
||||
|
||||
### Function: file(Filename)
|
||||
|
||||
#### Description
|
||||
|
||||
Same as:
|
||||
```erlang
|
||||
yamerl_constr:file(Filename, []).
|
||||
```
|
||||
|
||||
> See [`file/2`](#function-filefilename-options).
|
||||
|
||||
### Function: file(Filename, Options)
|
||||
|
||||
#### Arguments
|
||||
|
||||
* `Filename`: A string containing the filename to parse.
|
||||
* `Options`: A proplist of options; see [`new/2`](#function-newsource-options).
|
||||
|
||||
#### Description
|
||||
|
||||
Parse the file indicated by the given filename and return a list of constructed YAML documents.
|
||||
|
||||
The file is read by chunk of 4096 bytes (not configurable at this time).
|
||||
|
||||
Otherwise, the behavior is the same as [`string/2`](#function-stringstring-options).
|
||||
|
||||
> See [`string/2`](#function-stringstring-options) for return values, exceptions and examples.
|
@ -1,6 +0,0 @@
|
||||
# yamerl User Guide
|
||||
|
||||
## Recipes
|
||||
|
||||
* [Basic parsing](recipe-basic-parsing.md)
|
||||
* [Error handling](recipe-error-handling.md)
|
@ -1,48 +0,0 @@
|
||||
# Recipe: Basic parsing
|
||||
|
||||
1. Start the yamerl application. This is a mandatory step.
|
||||
|
||||
```erlang
|
||||
application:start(yamerl).
|
||||
```
|
||||
|
||||
2. You're now ready to parse a serialized document:
|
||||
|
||||
* To parse an in-memory string or binary:
|
||||
|
||||
```erlang
|
||||
Documents = yamerl_constr:string("Hello!").
|
||||
% Documents is a list of constructed documents.
|
||||
```
|
||||
|
||||
* To parse a file:
|
||||
|
||||
```erlang
|
||||
Documents = yamerl_constr:file("input.yaml").
|
||||
% Documents is a list of constructed documents.
|
||||
```
|
||||
|
||||
* To parse a stream:
|
||||
|
||||
```erlang
|
||||
% Create a new construction state. The only required argument is an
|
||||
% arbitrary term describing the source of the data. Here, we use the
|
||||
% same term structure as yamerl_constr:file/{1, 2}.
|
||||
Constr_State = yamerl_constr:new({file, "<stdin>"}),
|
||||
|
||||
% Feed the parser with binary chunks. The developer is responsible for
|
||||
% reading the chunk from the underlying source.
|
||||
%
|
||||
% The function returns an updated construction state, which replace the
|
||||
% previous one.
|
||||
%
|
||||
% yamerl_constr:next_chunk/2 can be called as many times as possible.
|
||||
{continue, Constr_State2} = yamerl_constr:next_chunk(Constr_State, Chunk),
|
||||
|
||||
% When the last chunk is reached, call yamerl_constr:last_chunk/2.
|
||||
Documents = yamerl_constr:last_chunk(Constr_State2, Last_Chunk).
|
||||
% Documents is a list of constructed documents.
|
||||
```
|
||||
|
||||
> For further informations, see:
|
||||
> * [yamerl\_constr module reference](../reference-manual/module-yamerl_constr.md);
|
@ -1,48 +0,0 @@
|
||||
# Recipe: Error handling
|
||||
|
||||
yamerl **throws an exception when an error occurs**.
|
||||
|
||||
1. Start the yamerl application. This is a mandatory step.
|
||||
|
||||
```erlang
|
||||
application:start(yamerl).
|
||||
```
|
||||
|
||||
2. You're now ready to parse a serialized document:
|
||||
|
||||
* To parse an in-memory string or binary:
|
||||
|
||||
```erlang
|
||||
-include_lib("yamerl/include/yamerl_errors.hrl").
|
||||
|
||||
% ...
|
||||
|
||||
try
|
||||
Documents = yamerl_constr:string("Hello!"),
|
||||
% Documents is a list of constructed documents.
|
||||
Documents
|
||||
catch
|
||||
throw:#yamerl_exception{errors = Errors} ->
|
||||
% Do something with the exception.
|
||||
Errors
|
||||
end.
|
||||
```
|
||||
|
||||
As you can see, the `#yamerl_exception{}` record embeds all encountered errors:
|
||||
```erlang
|
||||
#yamerl_exception{
|
||||
errors = [] % List of errors.
|
||||
}.
|
||||
```
|
||||
|
||||
Errors are records where the two first members are always:
|
||||
|
||||
1. `type`, either `error` or `warning`;
|
||||
2. `text`, a human-readable error message.
|
||||
|
||||
Following members depend on the error record. Two records are currently defined:
|
||||
* `#yamerl_invalid_option{}`;
|
||||
* `#yamerl_parsing_error{}`.
|
||||
|
||||
> For further informations, see:
|
||||
> * [yamerl\_constr module reference](../reference-manual/module-yamerl_constr.md);
|
237
doc/overview.edoc
Normal file
237
doc/overview.edoc
Normal file
@ -0,0 +1,237 @@
|
||||
@author Jean-Sébastien Pédron <jean-sebastien.pedron@dumbbell.fr>
|
||||
@copyright
|
||||
2012-2014 Yakaz,
|
||||
2016 Jean-Sébastien Pédron <jean-sebastien.pedron@dumbbell.fr>
|
||||
|
||||
@doc
|
||||
|
||||
== Introduction ==
|
||||
|
||||
YAML is a human-friendly data serialization format. The specification
|
||||
for this language and many examples are available from the <a
|
||||
href="http://www.yaml.org/">Official YAML web site</a>. You may also
|
||||
want to check the <a href="http://en.wikipedia.org/wiki/YAML">YAML
|
||||
Wikipedia article</a>.
|
||||
|
||||
<strong>`yamerl'</strong> is a pure <a
|
||||
href="http://www.erlang.org/">Erlang application</a> which is able
|
||||
to parse <a href="http://yaml.org/spec/1.1/">YAML 1.1</a> and <a
|
||||
href="http://www.yaml.org/spec/1.2/spec.html">YAML 1.2</a> documents, as
|
||||
well as <a href="http://json.org/">JSON</a> documents. It only depends
|
||||
on standard Erlang/OTP applications; no external dependency is required.
|
||||
It doesn't use native code either (neither port drivers nor NIFs). At
|
||||
this time, it has no support to serialize a YAML document.
|
||||
|
||||
`yamerl' is distributed under the terms of the <strong>2-clause BSD
|
||||
license</strong>; see `COPYING'.
|
||||
|
||||
== When to use yamerl or not ==
|
||||
|
||||
=== Advantages ===
|
||||
|
||||
<ul>
|
||||
<li>Pure Erlang implementation:
|
||||
<ul>
|
||||
<li>should scale more easily than a port-driver based implementation;</li>
|
||||
<li>won't take the whole VM down in case of a crash.</li>
|
||||
</ul></li>
|
||||
<li>YAML 1.2 support, which is not widely supported in many other languages.</li>
|
||||
</ul>
|
||||
|
||||
=== Caveats ===
|
||||
|
||||
<ul>
|
||||
<li>Current implementation is slow, compared to yamler (NIF-based) or any JSON-only parsers.</li>
|
||||
<li>Adding schemas is not easy.</li>
|
||||
<li>No support for YAML serialization.</li>
|
||||
</ul>
|
||||
|
||||
|
||||
== Features ==
|
||||
|
||||
<ul>
|
||||
<li>Supports <a href="http://www.yaml.org/spec/1.2/spec.html">YAML 1.2</a> parsing:
|
||||
```
|
||||
yamerl_constr:string("YAML snippet").
|
||||
'''</li>
|
||||
<li>Supports <a href="http://yaml.org/spec/1.1/">[YAML 1.1</a> parsing:
|
||||
```
|
||||
yamerl_constr:string("YAML snippet", [{schema, yaml11}]).
|
||||
'''</li>
|
||||
<li>Supports <a href="http://json.org/">JSON</a> parsing:
|
||||
```
|
||||
yamerl_constr:string(<<"JSON snippet">>, [{schema, json}]).
|
||||
'''</li>
|
||||
<li>Supports <strong>Erlang atom</strong> node type, either when tagged
|
||||
as atom, or if autodetected in plain scalars, and, if asked, only if the
|
||||
atom already exists:
|
||||
```
|
||||
% Enable support for Erlang atoms.
|
||||
yamerl_app:set_param(node_mods, [yamerl_node_erlang_atom]),
|
||||
yamerl_constr:string("!<tag:yamerl,2012:atom> atom").
|
||||
|
||||
% Autodetect Erlang atoms in plain scalars.
|
||||
yamerl_app:set_param(node_mods, [yamerl_node_erlang_atom]),
|
||||
yamerl_constr:string("atom", [{erlang_atom_autodetection, true}]).
|
||||
|
||||
% Atoms must already exist.
|
||||
yamerl_app:set_param(node_mods, [yamerl_node_erlang_atom]),
|
||||
yamerl_constr:string("atom", [
|
||||
{erlang_atom_autodetection, true},
|
||||
{erlang_atom_only_if_exist, true}
|
||||
]).
|
||||
'''</li>
|
||||
<li>Supports <strong>Erlang fun()</strong> node type:
|
||||
```
|
||||
% Enable support for Erlang fun().
|
||||
yamerl_app:set_param(node_mods, [yamerl_node_erlang_fun]),
|
||||
[Plus_One_Fun] = yamerl_constr:string(<<"!<tag:yamerl,2012:fun> fun(X) -> X + 1 end.">>),
|
||||
|
||||
Plus_One_Fun(2). % Return 3.
|
||||
'''</li>
|
||||
<li>Provides a <strong>yamler compatibility layer</strong>:
|
||||
```erlang
|
||||
% Both calls return the same value.
|
||||
yaml:load_file("input.yaml", [{schema, yaml_schema_failsafe}]),
|
||||
yamerl_yamler_compat:load_file("input.yaml", [{schema, yaml_schema_failsafe}])
|
||||
'''</li>
|
||||
</ul>
|
||||
|
||||
== Prerequisites ==
|
||||
|
||||
Before using yamerl, the application must be started:
|
||||
```
|
||||
application:start(yamerl).
|
||||
'''
|
||||
|
||||
This is required so that application environment variables are available.
|
||||
|
||||
Now, you can use the {@link yamerl_constr} module to parse and construct a
|
||||
list of documents from:
|
||||
<ul>
|
||||
<li>an in-memory document (string or binary);</li>
|
||||
<li>a regular file;</li>
|
||||
<li>a stream.</li>
|
||||
</ul>
|
||||
|
||||
Because a YAML input stream may contain multiple documents, {@link
|
||||
yamerl_constr} always returns a list of documents, even if the input
|
||||
stream only contains one.
|
||||
|
||||
== Examples ==
|
||||
|
||||
=== Basic parsing ===
|
||||
|
||||
<ol>
|
||||
<li>Start the yamerl application. This is a mandatory step.
|
||||
```
|
||||
application:start(yamerl).
|
||||
'''</li>
|
||||
<li>You're now ready to parse a serialized document:
|
||||
<ul>
|
||||
<li>To parse an in-memory string or binary:
|
||||
```
|
||||
Documents = yamerl_constr:string("Hello!").
|
||||
% Documents is a list of constructed documents.
|
||||
'''</li>
|
||||
<li>To parse a file:
|
||||
```
|
||||
Documents = yamerl_constr:file("input.yaml").
|
||||
% Documents is a list of constructed documents.
|
||||
'''</li>
|
||||
<li>To parse a stream:
|
||||
```
|
||||
% Create a new construction state. The only required argument is an
|
||||
% arbitrary term describing the source of the data. Here, we use the
|
||||
% same term structure as yamerl_constr:file/{1, 2}.
|
||||
Constr_State = yamerl_constr:new({file, "<stdin>"}),
|
||||
|
||||
% Feed the parser with binary chunks. The developer is responsible for
|
||||
% reading the chunk from the backing source.
|
||||
%
|
||||
% The function returns an updated construction state, which replaces the
|
||||
% previous one.
|
||||
%
|
||||
% yamerl_constr:next_chunk/2 can be called as many times as necessary.
|
||||
{continue, Constr_State2} = yamerl_constr:next_chunk(Constr_State, Chunk),
|
||||
|
||||
% When the last chunk is reached, call yamerl_constr:last_chunk/2.
|
||||
Documents = yamerl_constr:last_chunk(Constr_State2, Last_Chunk).
|
||||
% Documents is a list of constructed documents.
|
||||
'''</li>
|
||||
</ul></li>
|
||||
</ol>
|
||||
|
||||
See {@link yamerl_constr} for more informations.
|
||||
|
||||
=== Error handling ===
|
||||
|
||||
yamerl <strong>throws an exception when an error occurs</strong>.
|
||||
|
||||
<ol>
|
||||
<li>Start the yamerl application. This is a mandatory step.
|
||||
```
|
||||
application:start(yamerl).
|
||||
'''</li>
|
||||
<li>You're now ready to parse a serialized document. To parse an
|
||||
in-memory string or binary:
|
||||
```
|
||||
-include_lib("yamerl/include/yamerl_errors.hrl").
|
||||
|
||||
% ...
|
||||
|
||||
try
|
||||
Documents = yamerl_constr:string("Hello!"),
|
||||
% Documents is a list of constructed documents.
|
||||
Documents
|
||||
catch
|
||||
throw:#yamerl_exception{errors = Errors} ->
|
||||
% Do something with the exception.
|
||||
Errors
|
||||
end.
|
||||
'''</li>
|
||||
</ol>
|
||||
|
||||
As you can see, the `#yamerl_exception{}' record embeds all encountered
|
||||
errors:
|
||||
```
|
||||
#yamerl_exception{
|
||||
errors = [] % List of errors.
|
||||
}.
|
||||
'''
|
||||
|
||||
Errors are records where the two first members are always:
|
||||
<ol>
|
||||
<li>`type', either `error' or `warning';</li>
|
||||
<li>`text', a human-readable error message.</li>
|
||||
</ol>
|
||||
|
||||
Following members depend on the error record. Two records are currently
|
||||
defined:
|
||||
<ul>
|
||||
<li>`#yamerl_invalid_option{}';</li>
|
||||
<li>`#yamerl_parsing_error{}'.</li>
|
||||
</ul>
|
||||
|
||||
See {@link yamerl_constr} for more informations.
|
||||
|
||||
== Alternatives to yamerl ==
|
||||
|
||||
=== YAML parsers ===
|
||||
|
||||
<ul>
|
||||
<li><a href="https://github.com/goertzenator/yamler">yamler</a>:
|
||||
<ul>
|
||||
<li>Based on libyaml, wrapped in a NIF</li>
|
||||
<li>Supports YAML 1.1</li>
|
||||
<li>Faster than yamerl</li>
|
||||
<li>Supports Erlang atoms, however, single-quoted scalar are treated as
|
||||
atom, which breaks the YAML specifications</li>
|
||||
<li>Doesn't support Erlang fun()</li>
|
||||
</ul></li>
|
||||
</ul>
|
||||
|
||||
=== JSON parsers ===
|
||||
|
||||
There are too many to choose from now to list them here. Use your
|
||||
preferred search engine :-)
|
@ -1,41 +0,0 @@
|
||||
beamdir = $(ERLANG_INSTALL_LIB_DIR_yamerl)/ebin
|
||||
|
||||
APP_NAME = $(PACKAGE_NAME)
|
||||
APP_FILES = $(APP_NAME).app $(APP_NAME).appup
|
||||
|
||||
BEAM_FILES = *.beam
|
||||
|
||||
beam_DATA = $(APP_FILES) $(BEAM_FILES)
|
||||
|
||||
CLEANFILES = $(APP_NAME).app $(BEAM_FILES)
|
||||
|
||||
# $(APP_NAME).app is generated automatically with all the BEAM files
|
||||
# present in the ebin/ directory.
|
||||
$(APP_NAME).app: Makefile.am $(APP_NAME).app.in
|
||||
@echo "Generate: $@"
|
||||
@src=`echo $$(ls $(BEAM_FILES) | sort)`; \
|
||||
$(AWK) -v src="$$src" \
|
||||
"/{vsn, *{cmd,/ { \
|
||||
line = \$$0; \
|
||||
sub(/{vsn.*/, \"{vsn, \\\"$(VERSION)\\\"},\", line); \
|
||||
print line; \
|
||||
next; \
|
||||
} \
|
||||
{ print; } \
|
||||
/% DO NOT EDIT: Modules list is generated/ { \
|
||||
indent = index(\$$0, \"%\"); \
|
||||
indent = substr(\$$0, 1, indent - 1); \
|
||||
split(src, mods); \
|
||||
mods_count = 0; \
|
||||
for (mod in mods) { \
|
||||
mods_count++ \
|
||||
} \
|
||||
for (i = 1; i <= mods_count; i++) { \
|
||||
mod = mods[i]; \
|
||||
sub(/\.beam/, \"\", mod); \
|
||||
if (i != mods_count) \
|
||||
print indent mod \",\"; \
|
||||
else \
|
||||
print indent mod \
|
||||
} \
|
||||
}" $(APP_NAME).app.in > $@
|
@ -1 +0,0 @@
|
||||
../src/yamerl.app.src
|
@ -1,10 +0,0 @@
|
||||
%% -*-erlang-*-
|
||||
%% vim:ft=erlang:
|
||||
|
||||
{ "@VERSION@",
|
||||
[
|
||||
%% To upgrade from the specified version to current one.
|
||||
], [
|
||||
%% To downgrade from the current version to the specified one.
|
||||
]
|
||||
}.
|
@ -1,9 +0,0 @@
|
||||
headersdir = $(ERLANG_INSTALL_LIB_DIR_yamerl)/include
|
||||
|
||||
nobase_dist_headers_DATA = yamerl_types.hrl \
|
||||
yamerl_errors.hrl \
|
||||
yamerl_tokens.hrl \
|
||||
yamerl_nodes.hrl \
|
||||
yamerl_nodes_yamerl_extensions.hrl \
|
||||
internal/yamerl_parser.hrl \
|
||||
internal/yamerl_constr.hrl
|
@ -48,12 +48,12 @@
|
||||
%% -------------------------------------------------------------------
|
||||
|
||||
-record(impl_key, {
|
||||
possible = false :: boolean(),
|
||||
required :: boolean(),
|
||||
line :: position(),
|
||||
col :: position(),
|
||||
chars_idx :: pos_integer(),
|
||||
token_idx :: pos_integer()
|
||||
possible = false :: boolean(),
|
||||
required = false :: boolean(),
|
||||
line :: position() | undefined,
|
||||
col :: position() | undefined,
|
||||
chars_idx = 1 :: pos_integer(),
|
||||
token_idx = 1 :: pos_integer()
|
||||
}).
|
||||
|
||||
-record(bcoll, {
|
||||
|
@ -1,94 +0,0 @@
|
||||
dnl Macro to compare version numbers in configure.
|
||||
dnl
|
||||
|
||||
AC_DEFUN([AX_COMPARE_VERSION], [
|
||||
# Used to indicate true or false condition
|
||||
ax_compare_version=false
|
||||
|
||||
# Convert the two version strings to be compared into a format that
|
||||
# allows a simple string comparison. The end result is that a version
|
||||
# string of the form 1.12.5-r617 will be converted to the form
|
||||
# 0001001200050617. In other words, each number is zero padded to four
|
||||
# digits, and non digits are removed.
|
||||
AS_VAR_PUSHDEF([A],[ax_compare_version_A])
|
||||
A=`echo "$1" | sed -e 's/\([[0-9]]*\)/Z\1Z/g' \
|
||||
-e 's/Z\([[0-9]]\)Z/Z0\1Z/g' \
|
||||
-e 's/Z\([[0-9]][[0-9]]\)Z/Z0\1Z/g' \
|
||||
-e 's/Z\([[0-9]][[0-9]][[0-9]]\)Z/Z0\1Z/g' \
|
||||
-e 's/[[^0-9]]//g'`
|
||||
|
||||
AS_VAR_PUSHDEF([B],[ax_compare_version_B])
|
||||
B=`echo "$3" | sed -e 's/\([[0-9]]*\)/Z\1Z/g' \
|
||||
-e 's/Z\([[0-9]]\)Z/Z0\1Z/g' \
|
||||
-e 's/Z\([[0-9]][[0-9]]\)Z/Z0\1Z/g' \
|
||||
-e 's/Z\([[0-9]][[0-9]][[0-9]]\)Z/Z0\1Z/g' \
|
||||
-e 's/[[^0-9]]//g'`
|
||||
|
||||
dnl # In the case of le, ge, lt, and gt, the strings are sorted as necessary
|
||||
dnl # then the first line is used to determine if the condition is true.
|
||||
dnl # The sed right after the echo is to remove any indented white space.
|
||||
m4_case(m4_tolower($2),
|
||||
[lt],[
|
||||
ax_compare_version=`echo "x$A
|
||||
x$B" | sed 's/^ *//' | sort -r | sed "s/x${A}/false/;s/x${B}/true/;1q"`
|
||||
],
|
||||
[gt],[
|
||||
ax_compare_version=`echo "x$A
|
||||
x$B" | sed 's/^ *//' | sort | sed "s/x${A}/false/;s/x${B}/true/;1q"`
|
||||
],
|
||||
[le],[
|
||||
ax_compare_version=`echo "x$A
|
||||
x$B" | sed 's/^ *//' | sort | sed "s/x${A}/true/;s/x${B}/false/;1q"`
|
||||
],
|
||||
[ge],[
|
||||
ax_compare_version=`echo "x$A
|
||||
x$B" | sed 's/^ *//' | sort -r | sed "s/x${A}/true/;s/x${B}/false/;1q"`
|
||||
],[
|
||||
dnl Split the operator from the subversion count if present.
|
||||
m4_bmatch(m4_substr($2,2),
|
||||
[0],[
|
||||
# A count of zero means use the length of the shorter version.
|
||||
# Determine the number of characters in A and B.
|
||||
ax_compare_version_len_A=`echo "$A" | awk '{print(length)}'`
|
||||
ax_compare_version_len_B=`echo "$B" | awk '{print(length)}'`
|
||||
|
||||
# Set A to no more than B's length and B to no more than A's length.
|
||||
A=`echo "$A" | sed "s/\(.\{$ax_compare_version_len_B\}\).*/\1/"`
|
||||
B=`echo "$B" | sed "s/\(.\{$ax_compare_version_len_A\}\).*/\1/"`
|
||||
],
|
||||
[[0-9]+],[
|
||||
# A count greater than zero means use only that many subversions
|
||||
A=`echo "$A" | sed "s/\(\([[0-9]]\{4\}\)\{m4_substr($2,2)\}\).*/\1/"`
|
||||
B=`echo "$B" | sed "s/\(\([[0-9]]\{4\}\)\{m4_substr($2,2)\}\).*/\1/"`
|
||||
],
|
||||
[.+],[
|
||||
AC_WARNING(
|
||||
[illegal OP numeric parameter: $2])
|
||||
],[])
|
||||
|
||||
# Pad zeros at end of numbers to make same length.
|
||||
ax_compare_version_tmp_A="$A`echo $B | sed 's/./0/g'`"
|
||||
B="$B`echo $A | sed 's/./0/g'`"
|
||||
A="$ax_compare_version_tmp_A"
|
||||
|
||||
# Check for equality or inequality as necessary.
|
||||
m4_case(m4_tolower(m4_substr($2,0,2)),
|
||||
[eq],[
|
||||
test "x$A" = "x$B" && ax_compare_version=true
|
||||
],
|
||||
[ne],[
|
||||
test "x$A" != "x$B" && ax_compare_version=true
|
||||
],[
|
||||
AC_WARNING([illegal OP parameter: $2])
|
||||
])
|
||||
])
|
||||
|
||||
AS_VAR_POPDEF([A])dnl
|
||||
AS_VAR_POPDEF([B])dnl
|
||||
|
||||
dnl # Execute ACTION-IF-TRUE / ACTION-IF-FALSE.
|
||||
if test "$ax_compare_version" = "true" ; then
|
||||
m4_ifvaln([$4],[$4],[:])dnl
|
||||
m4_ifvaln([$5],[else $5])dnl
|
||||
fi
|
||||
]) dnl AX_COMPARE_VERSION
|
@ -1,75 +0,0 @@
|
||||
dnl
|
||||
dnl Macro to output bold and colored text.
|
||||
dnl
|
||||
|
||||
dnl COLORED_ECHO_INIT
|
||||
dnl This macro must be called first to initialize a context.
|
||||
AC_DEFUN([COLORED_ECHO_INIT],
|
||||
[
|
||||
dnl Prepare fancy console output, taken from GNU shtools.
|
||||
colored_echo_bold=''
|
||||
colored_echo_norm=''
|
||||
|
||||
AC_PROG_AWK
|
||||
if test x"$AWK" = x"not found"; then
|
||||
return
|
||||
fi
|
||||
|
||||
case $TERM in
|
||||
xterm|xterm*|vt220|vt220*)
|
||||
dnl For the most important terminal types we directly know the
|
||||
dnl sequences.
|
||||
colored_echo_bold=`$AWK 'BEGIN { printf("%c%c%c%c", 27, 91, 49, 109); }' </dev/null 2>/dev/null`
|
||||
colored_echo_norm=`$AWK 'BEGIN { printf("%c%c%c", 27, 91, 109); }' </dev/null 2>/dev/null`
|
||||
;;
|
||||
|
||||
vt100|vt100*|cygwin)
|
||||
colored_echo_bold=`$AWK 'BEGIN { printf("%c%c%c%c%c%c", 27, 91, 49, 109, 0, 0); }' </dev/null 2>/dev/null`
|
||||
colored_echo_norm=`$AWK 'BEGIN { printf("%c%c%c%c%c", 27, 91, 109, 0, 0); }' </dev/null 2>/dev/null`
|
||||
;;
|
||||
|
||||
*)
|
||||
dnl For all others, we try to use a possibly existing `tput' or
|
||||
dnl `tcout' utility.
|
||||
paths=`$ECHO $PATH | sed -e 's/:/ /g'`
|
||||
for tool in tput tcout; do
|
||||
for dir in $paths; do
|
||||
if test -r "$dir/$tool" ; then
|
||||
for seq in bold md smso; do
|
||||
bold="`$dir/$tool $seq 2>/dev/null`"
|
||||
if test ".$bold" != . ; then
|
||||
colored_echo_bold="$bold"
|
||||
break
|
||||
fi
|
||||
done
|
||||
if test ".$colored_echo_bold" != . ; then
|
||||
for seq in sgr0 me rmso init reset; do
|
||||
norm="`$dir/$tool $seq 2>/dev/null`"
|
||||
if test ".$norm" != . ; then
|
||||
colored_echo_norm="$norm"
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
break
|
||||
fi
|
||||
done
|
||||
if test x"$colored_echo_bold" != "x" -a x"$colored_echo_norm" != "x"; then
|
||||
break;
|
||||
fi
|
||||
done
|
||||
;;
|
||||
esac
|
||||
])
|
||||
|
||||
dnl COLORED_ECHO(TEXT)
|
||||
dnl Output text with:
|
||||
dnl o everything between %B and %b displayed bold.
|
||||
AC_DEFUN([COLORED_ECHO],
|
||||
[
|
||||
text=`$ECHO $seo "$1" | sed -e "s/%B/${colored_echo_bold}/g" -e "s/%b/${colored_echo_norm}/g" 2>/dev/null`
|
||||
$ECHO $seo "$text"
|
||||
|
||||
text=`$ECHO $sec "$1" | sed -e "s/%B//g" -e "s/%b//g" 2>/dev/null`
|
||||
_AS_ECHO_LOG($text)
|
||||
])
|
68
m4/erlang.m4
68
m4/erlang.m4
@ -1,68 +0,0 @@
|
||||
dnl
|
||||
dnl More functions to query Erlang environment.
|
||||
dnl
|
||||
|
||||
dnl ERLANG_CHECK_ERTS([ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]])
|
||||
dnl Substitudes
|
||||
dnl ERLANG_ERTS_DIR
|
||||
dnl ERLANG_ERTS_VER
|
||||
AC_DEFUN([ERLANG_CHECK_ERTS],
|
||||
[
|
||||
AC_REQUIRE([AC_ERLANG_PATH_ERLC])[]dnl
|
||||
AC_REQUIRE([AC_ERLANG_PATH_ERL])[]dnl
|
||||
AC_REQUIRE([AC_ERLANG_SUBST_ROOT_DIR])[]dnl
|
||||
AC_CACHE_CHECK([for Erlang/OTP ERTS version],
|
||||
[erlang_cv_erts_ver],
|
||||
[
|
||||
AC_LANG_PUSH(Erlang)[]dnl
|
||||
AC_RUN_IFELSE(
|
||||
[AC_LANG_PROGRAM([], [dnl
|
||||
file:write_file("conftest.out", erlang:system_info(version)),
|
||||
halt(0)])],
|
||||
[erlang_cv_erts_ver=`cat conftest.out`],
|
||||
[if test ! -f conftest.out; then
|
||||
AC_MSG_FAILURE([test Erlang program execution failed])
|
||||
else
|
||||
erlang_cv_erts_ver="not found"
|
||||
fi])
|
||||
AC_LANG_POP(Erlang)[]dnl
|
||||
])
|
||||
AC_CACHE_CHECK([for Erlang/OTP ERTS directory],
|
||||
[erlang_cv_erts_dir],
|
||||
[
|
||||
erlang_cv_erts_dir="${ERLANG_ROOT_DIR}/erts-$erlang_cv_erts_ver"
|
||||
if test ! -d "$erlang_cv_erts_dir"; then
|
||||
erlang_cv_erts_dir="${ERLANG_ROOT_DIR}/usr"
|
||||
fi
|
||||
])
|
||||
AC_SUBST([ERLANG_ERTS_DIR], [$erlang_cv_erts_dir])
|
||||
AC_SUBST([ERLANG_ERTS_VER], [$erlang_cv_erts_ver])
|
||||
AS_IF([test "$erlang_cv_erts_ver" = "not found"], [$2], [$1])
|
||||
])
|
||||
|
||||
dnl ERLANG_CHECK_RELEASE()
|
||||
dnl Substitudes
|
||||
dnl ERLANG_RELEASE
|
||||
AC_DEFUN([ERLANG_CHECK_RELEASE],
|
||||
[
|
||||
AC_REQUIRE([AC_ERLANG_PATH_ERLC])[]dnl
|
||||
AC_REQUIRE([AC_ERLANG_PATH_ERL])[]dnl
|
||||
AC_REQUIRE([AC_ERLANG_SUBST_ROOT_DIR])[]dnl
|
||||
AC_CACHE_CHECK([for Erlang/OTP release],
|
||||
[erlang_cv_release],
|
||||
[
|
||||
AC_LANG_PUSH(Erlang)[]dnl
|
||||
AC_RUN_IFELSE(
|
||||
[AC_LANG_PROGRAM([], [dnl
|
||||
file:write_file("conftest.out", erlang:system_info(otp_release)),
|
||||
halt(0)])],
|
||||
[erlang_cv_release=`cat conftest.out`],
|
||||
[if test ! -f conftest.out; then
|
||||
AC_MSG_FAILURE([test Erlang program execution failed])
|
||||
else
|
||||
erlang_cv_release="not found"
|
||||
fi])
|
||||
AC_LANG_POP(Erlang)[]dnl
|
||||
])
|
||||
AC_SUBST([ERLANG_RELEASE], [$erlang_cv_release])
|
||||
])
|
54
mix.exs
54
mix.exs
@ -1,54 +0,0 @@
|
||||
defmodule Yamerl.Mixfile do
|
||||
use Mix.Project
|
||||
|
||||
def project do
|
||||
[
|
||||
app: :yamerl,
|
||||
version: "0.3.3",
|
||||
description: description,
|
||||
package: package,
|
||||
deps: deps(),
|
||||
|
||||
# Docs.
|
||||
name: "yamerl",
|
||||
source_url: "https://github.com/yakaz/yamerl",
|
||||
homepage_url: "https://github.com/yakaz/yamerl",
|
||||
docs: [
|
||||
extras: [
|
||||
"doc-md/features.md",
|
||||
"doc-md/installation.md",
|
||||
"doc-md/user-guide/recipe-error-handling.md",
|
||||
"doc-md/user-guide/recipe-basic-parsing.md",
|
||||
"doc-md/reference-manual/module-yamerl_constr.md",
|
||||
"doc-md/alternatives.md"
|
||||
]
|
||||
]
|
||||
]
|
||||
end
|
||||
|
||||
defp description do
|
||||
"""
|
||||
YAML 1.2 parser in pure Erlang
|
||||
"""
|
||||
end
|
||||
|
||||
defp deps do
|
||||
[
|
||||
{:ex_doc, ">= 0.0.0", only: :dev}
|
||||
]
|
||||
end
|
||||
|
||||
defp package do
|
||||
[
|
||||
files: ~w(src doc-md include testsuite configure.ac rebar.config README.md AUTHORS COPYING),
|
||||
maintainers: ["Jean-Sébastien Pédron <jean-sebastien.pedron@dumbbell.fr>"],
|
||||
contributors: ["Yakaz", "Jean-Sébastien Pédron <jean-sebastien.pedron@dumbbell.fr>"],
|
||||
licenses: ["BSD 2-Clause"],
|
||||
links: %{
|
||||
"GitHub" => "https://github.com/yakaz/yamerl",
|
||||
"Doc" => "https://github.com/yakaz/yamerl/tree/master/doc"
|
||||
}
|
||||
]
|
||||
end
|
||||
|
||||
end
|
@ -1,10 +1,2 @@
|
||||
%% -*-erlang-*-
|
||||
%% vim:ft=erlang:
|
||||
|
||||
{pre_hooks, [
|
||||
{eunit, "./testsuite/prepare-testsuite-for-rebar"}
|
||||
]}.
|
||||
|
||||
{post_hooks, [
|
||||
{clean, "rm -rf test"}
|
||||
]}.
|
||||
|
@ -1,14 +0,0 @@
|
||||
%% -*-erlang-*-
|
||||
%% vim:ft=erlang:
|
||||
|
||||
{
|
||||
[
|
||||
%% DO NOT EDIT: Modules list is generated by Makefile.am.
|
||||
],
|
||||
[
|
||||
@EMKOPTS@,
|
||||
{outdir, "@builddir@/../ebin"},
|
||||
{i, "@top_srcdir@/include"},
|
||||
{i, "@top_builddir@/include"}
|
||||
]
|
||||
}.
|
@ -1,71 +0,0 @@
|
||||
erlsrcdir = $(ERLANG_INSTALL_LIB_DIR_yamerl)/src
|
||||
|
||||
dist_erlsrc_DATA = yamerl_app.erl \
|
||||
yamerl_sup.erl \
|
||||
yamerl_errors.erl \
|
||||
yamerl_parser.erl \
|
||||
yamerl_constr.erl \
|
||||
yamerl_node_seq.erl \
|
||||
yamerl_node_map.erl \
|
||||
yamerl_node_str.erl \
|
||||
yamerl_node_str_json.erl \
|
||||
yamerl_node_null.erl \
|
||||
yamerl_node_null_json.erl \
|
||||
yamerl_node_bool.erl \
|
||||
yamerl_node_bool_json.erl \
|
||||
yamerl_node_bool_ext.erl \
|
||||
yamerl_node_int.erl \
|
||||
yamerl_node_int_json.erl \
|
||||
yamerl_node_int_ext.erl \
|
||||
yamerl_node_float.erl \
|
||||
yamerl_node_float_json.erl \
|
||||
yamerl_node_float_ext.erl \
|
||||
yamerl_node_size.erl \
|
||||
yamerl_node_timestamp.erl \
|
||||
yamerl_node_ipaddr.erl \
|
||||
yamerl_node_erlang_atom.erl \
|
||||
yamerl_node_erlang_fun.erl \
|
||||
yamerl_yamler_compat.erl \
|
||||
yamerl.erl
|
||||
|
||||
CLEANFILES = Emakefile
|
||||
|
||||
all-local: Emakefile
|
||||
@$(ERL) +B -noshell \
|
||||
-pa @top_builddir@/ebin \
|
||||
-eval "case make:all() of \
|
||||
up_to_date -> \
|
||||
halt(0); \
|
||||
Err -> \
|
||||
io:format(\"~p~n\", [Err]), \
|
||||
halt(1) \
|
||||
end"
|
||||
|
||||
# Emakefile is generated automatically with the source files declared above.
|
||||
Emakefile: Makefile.am Emakefile.in
|
||||
@echo "Generate: $@"
|
||||
@$(AWK) -v src='$(dist_erlsrc_DATA)' \
|
||||
"{ print } \
|
||||
/% DO NOT EDIT: Modules list is generated/ { \
|
||||
indent = index(\$$0, \"%\"); \
|
||||
indent = substr(\$$0, 1, indent - 1); \
|
||||
split(src, files); \
|
||||
files_count = 0; \
|
||||
for (file in files) { \
|
||||
files_count++ \
|
||||
} \
|
||||
mods_count = 0; \
|
||||
for (i = 1; i <= files_count; i++) { \
|
||||
if (files[i] !~ /\.erl$$/) \
|
||||
continue; \
|
||||
mods[++mods_count] = files[i] \
|
||||
} \
|
||||
for (i = 1; i <= mods_count; i++) { \
|
||||
mod = mods[i]; \
|
||||
sub(/\.erl/, \"\", mod); \
|
||||
if (i != mods_count) \
|
||||
print indent \"'$(srcdir)/\" mod \"',\";\
|
||||
else \
|
||||
print indent \"'$(srcdir)/\" mod \"'\" \
|
||||
} \
|
||||
}" Emakefile.in > $@
|
@ -5,10 +5,8 @@
|
||||
{description,
|
||||
"YAML parser in pure Erlang"
|
||||
},
|
||||
{vsn, {cmd, "awk '/^AC_INIT\\(/ { ver=$0; sub(/AC_INIT\\(\\[[^]]+\\], *\\[/, \"\", ver); sub(/\\].*/, \"\", ver); print ver; } { next; }' configure.ac"}},
|
||||
{modules, [
|
||||
%% DO NOT EDIT: Modules list is generated by Makefile.am.
|
||||
]},
|
||||
{vsn, "0.4.0"},
|
||||
{modules, []},
|
||||
{registered, [yamerl_sup]},
|
||||
{applications, [
|
||||
kernel,
|
||||
@ -20,24 +18,13 @@
|
||||
%% DO NOT EDIT: The final configuration is made in sys.config.
|
||||
{node_mods, []}
|
||||
]},
|
||||
|
||||
%% Hex.pm package informations.
|
||||
{maintainers, [
|
||||
"Yakaz",
|
||||
"Jean-Sebastien Pedron <jean-sebastien.pedron@dumbbell.fr>"
|
||||
]},
|
||||
{licenses, ["BSD 2-Clause"]},
|
||||
{links, [
|
||||
{"GitHub", "https://github.com/yakaz/yamerl"},
|
||||
{"Doc", "https://github.com/yakaz/yamerl/tree/master/doc"}
|
||||
]},
|
||||
{files, [
|
||||
"rebar.config",
|
||||
"configure.ac", % The package version is taken there.
|
||||
"include/*.hrl",
|
||||
"include/internal/*.hrl",
|
||||
"src/yamerl.app.src",
|
||||
"src/*.erl",
|
||||
"README.md",
|
||||
"AUTHORS",
|
||||
"COPYING"
|
||||
{"Github", "https://github.com/yakaz/yamerl"}
|
||||
]}
|
||||
]}.
|
||||
|
@ -24,6 +24,13 @@
|
||||
% OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
% SUCH DAMAGE.
|
||||
|
||||
%% @author Jean-Sébastien Pédron <jean-sebastien.pedron@dumbbell.fr>
|
||||
%% @copyright
|
||||
%% 2012-2014 Yakaz,
|
||||
%% 2016 Jean-Sébastien Pédron <jean-sebastien.pedron@dumbbell.fr>
|
||||
%%
|
||||
%% @doc Wrappers for common uses of {@link yamerl_constr}.
|
||||
|
||||
-module(yamerl).
|
||||
|
||||
-include("yamerl_nodes.hrl").
|
||||
@ -44,6 +51,8 @@
|
||||
%% All those functions are only wrapper above yamerl_constr common
|
||||
%% functions. The purpose is just to avoid some typing.
|
||||
|
||||
%% @equiv yamerl_constr:string(String)
|
||||
|
||||
-spec decode(String) ->
|
||||
Result | no_return() when
|
||||
String :: unicode_data(),
|
||||
@ -54,6 +63,8 @@
|
||||
decode(String) ->
|
||||
yamerl_constr:string(String).
|
||||
|
||||
%% @equiv yamerl_constr:string(String, Options)
|
||||
|
||||
-spec decode(String, Options) ->
|
||||
Result | no_return() when
|
||||
String :: unicode_data(),
|
||||
@ -67,6 +78,8 @@ decode(String) ->
|
||||
decode(String, Options) ->
|
||||
yamerl_constr:string(String, Options).
|
||||
|
||||
%% @equiv yamerl_constr:file(Filename)
|
||||
|
||||
-spec decode_file(Filename) ->
|
||||
Result | no_return() when
|
||||
Filename :: string(),
|
||||
@ -77,6 +90,8 @@ decode(String, Options) ->
|
||||
decode_file(Filename) ->
|
||||
yamerl_constr:file(Filename).
|
||||
|
||||
%% @equiv yamerl_constr:file(Filename, Options)
|
||||
|
||||
-spec decode_file(Filename, Options) ->
|
||||
Result | no_return() when
|
||||
Filename :: string(),
|
||||
|
@ -24,6 +24,8 @@
|
||||
% OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
% SUCH DAMAGE.
|
||||
|
||||
%% @private
|
||||
|
||||
-module(yamerl_app).
|
||||
|
||||
-behaviour(application).
|
||||
|
@ -24,6 +24,64 @@
|
||||
% OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
% SUCH DAMAGE.
|
||||
|
||||
%% @author Jean-Sébastien Pédron <jean-sebastien.pedron@dumbbell.fr>
|
||||
%% @copyright
|
||||
%% 2012-2014 Yakaz,
|
||||
%% 2016 Jean-Sébastien Pédron <jean-sebastien.pedron@dumbbell.fr>
|
||||
%%
|
||||
%% @doc {@module} implements a YAML constructor. It uses {@link
|
||||
%% yamerl_parser} as the underlying parser. The parser emits YAML nodes
|
||||
%% which are assembled as structured YAML documents by the constructor.
|
||||
%%
|
||||
%% It is able to construct YAML documents from in-memory strings (see
|
||||
%% {@link string/1} and {@link string/2}), regular files (see {@link
|
||||
%% file/1} and {@link file/2}) or streams (see {@link new/1}, {@link
|
||||
%% new/2} and {@link next_chunk/3}).
|
||||
%%
|
||||
%% YAML documents can be constructed in simple or detailed modes. In
|
||||
%% simple mode, they are made of simple builting Erlang types. In
|
||||
%% detailed mode, they are made of records, holding more informations
|
||||
%% about YAML nodes and their presentation.
|
||||
%%
|
||||
%% The `yamerl' application must be started to use the constructor.
|
||||
%%
|
||||
%% <strong>Example: parse a string in simple mode</strong>
|
||||
%% ```
|
||||
%% yamerl_constr:string("Hello!").
|
||||
%% '''
|
||||
%%
|
||||
%% It returns:
|
||||
%% ```
|
||||
%% % List of documents; here, only one.
|
||||
%% [
|
||||
%% % Document root node: a string.
|
||||
%% "Hello!"
|
||||
%% ].
|
||||
%% '''
|
||||
%%
|
||||
%% <strong>Example: parse a stream in detailed mode</strong>
|
||||
%% ```
|
||||
%% Stream_St1 = yamerl_constr:new({file, "<stdin>"}, [{detailed_constr, true}]),
|
||||
%% {continue, Stream_St2} = yamerl_constr:next_chunk(Stream_St1, <<"He">>),
|
||||
%% {continue, Stream_St3} = yamerl_constr:next_chunk(Stream_St2, <<"ll">>),
|
||||
%% yamerl_constr:last_chunk(Stream_St3, <<"o!">>).
|
||||
%% '''
|
||||
%%
|
||||
%% It returns:
|
||||
%% ```
|
||||
%% % List of documents; here, only one.
|
||||
%% [
|
||||
%% % Document #1.
|
||||
%% {yamerl_doc,
|
||||
%% % Document root node: a string.
|
||||
%% {yamerl_str, yamerl_node_str, "tag:yaml.org,2002:str",
|
||||
%% [{line, 1}, {column, 1}], % Node location in the original string.
|
||||
%% "Hello!" % String value.
|
||||
%% }
|
||||
%% }
|
||||
%% ].
|
||||
%% '''
|
||||
|
||||
-module(yamerl_constr).
|
||||
|
||||
-include("yamerl_errors.hrl").
|
||||
@ -96,6 +154,8 @@
|
||||
%% Public API: chunked stream scanning.
|
||||
%% -------------------------------------------------------------------
|
||||
|
||||
%% @equiv new(Source, [])
|
||||
|
||||
-spec new(Source) ->
|
||||
Constr | no_return() when
|
||||
Source :: term(),
|
||||
@ -104,29 +164,141 @@
|
||||
new(Source) ->
|
||||
new(Source, []).
|
||||
|
||||
%% @doc Creates and returns a new YAML construction state.
|
||||
%%
|
||||
%% When you want to parse a stream (as opposed to in-memory strings or
|
||||
%% regular files), this is the first function you call before feeding
|
||||
%% the constructor with stream "chunks".
|
||||
%%
|
||||
%% `Source' can be any term describing the stream. {@link string/1} and
|
||||
%% {@link string/2} sets it to the atom `string'. {@link file/1} and
|
||||
%% {@link file/2} sets it to `{file, Filename}'. The constructor doesn't
|
||||
%% use that value.
|
||||
%%
|
||||
%% `Options' is a list of options for the parser and the constructor.
|
||||
%% Valid options are:
|
||||
%%
|
||||
%% <dl>
|
||||
%% <dt>`{detailed_constr, boolean()}'</dt>
|
||||
%% <dd>Flag to enable/disable the detailed construction mode. In simple
|
||||
%% construction mode, YAML nodes are returned as Erlang integers,
|
||||
%% strings, lists, proplists, etc. In other words, only simple builtin
|
||||
%% types. In detailed construction mode, YAML nodes are returned using
|
||||
%% records. Those records gives additional informations such as the YAML
|
||||
%% node type, the location in the stream (line and column number) and so
|
||||
%% on.</dd>
|
||||
%% <dd>Default: `false'</dd>
|
||||
%% <dt>`{schema, failsafe | json | core | yaml11}'</dt>
|
||||
%% <dd>Name of the official schema to use.</dd>
|
||||
%% <dd>Default: `core'.</dd>
|
||||
%% <dt>`{node_mods, Mods_List}'</dt>
|
||||
%% <dd>List of Erlang modules to extend support node types.</dd>
|
||||
%% <dd>Default: `[]'.</dd>
|
||||
%% </dl>
|
||||
%%
|
||||
%% The returned state is opaque value. You then pass it to {@link
|
||||
%% next_chunk/2}, {@link next_chunk/3} and {@link last_chunk/2}.
|
||||
%%
|
||||
%% If an option is invalid, an exception is thrown.
|
||||
%%
|
||||
%% <strong>Example: parse a valid stream</strong>
|
||||
%% ```
|
||||
%% Stream_St1 = yamerl_constr:new({file, "<stdin>"}),
|
||||
%% {continue, Stream_St2} = yamerl_constr:next_chunk(Stream_St1, <<"He">>),
|
||||
%% {continue, Stream_St3} = yamerl_constr:next_chunk(Stream_St2, <<"ll">>),
|
||||
%% yamerl_constr:last_chunk(Stream_St3, <<"o!">>).
|
||||
%% '''
|
||||
%% It returns:
|
||||
%%
|
||||
%% ```
|
||||
%% % List of documents; here, only one.
|
||||
%% [
|
||||
%% % Document root node: a string.
|
||||
%% "Hello!"
|
||||
%% ].
|
||||
%% '''
|
||||
%%
|
||||
%% <strong>Example: parse an invalid stream</strong>
|
||||
%% ```
|
||||
%% Stream_St1 = yamerl_constr:new({file, "<stdin>"}),
|
||||
%% {continue, Stream_St2} = yamerl_constr:next_chunk(Stream_St1, <<"'He">>),
|
||||
%% {continue, Stream_St3} = yamerl_constr:next_chunk(Stream_St2, <<"ll">>),
|
||||
%% yamerl_constr:last_chunk(Stream_St3, <<"o!">>) % Unfinished single-quoted scalar.
|
||||
%% '''
|
||||
%%
|
||||
%% It throws:
|
||||
%% ```
|
||||
%% {yamerl_exception,
|
||||
%% % List of warnings and errors; here, one fatal error.
|
||||
%% [
|
||||
%% % Error #1.
|
||||
%% {yamerl_parsing_error, error,
|
||||
%% "Unexpected end-of-stream while parsing flow scalar", % Human-readable message.
|
||||
%% 1, 8, % Error location.
|
||||
%% unexpected_eos,
|
||||
%% {yamerl_scalar, 1, 1, {yamerl_tag, 1, 1, {non_specific, "!"}}, % Token being parsed.
|
||||
%% flow, single_quoted,
|
||||
%% "Hello!"},
|
||||
%% []
|
||||
%% }
|
||||
%% ]
|
||||
%% }
|
||||
%% '''
|
||||
%%
|
||||
%% @see new/1.
|
||||
|
||||
-spec new(Source, Options) ->
|
||||
Constr | no_return() when
|
||||
Source :: term(),
|
||||
Options :: [
|
||||
yamerl_constr_option() |
|
||||
yamerl_parser:yamerl_parser_option() |
|
||||
proplists:property()
|
||||
],
|
||||
Constr :: yamerl_parser:yamerl_parser().
|
||||
Constr | no_return() when
|
||||
Source :: term(),
|
||||
Options :: [
|
||||
yamerl_constr_option() |
|
||||
yamerl_parser:yamerl_parser_option() |
|
||||
proplists:property()
|
||||
],
|
||||
Constr :: yamerl_parser:yamerl_parser().
|
||||
|
||||
new(Source, Options) ->
|
||||
Parser_Options = initialize(Options),
|
||||
yamerl_parser:new(Source, Parser_Options).
|
||||
Parser_Options = initialize(Options),
|
||||
yamerl_parser:new(Source, Parser_Options).
|
||||
|
||||
%% @equiv next_chunk(Constr, Chunk, false)
|
||||
|
||||
-spec next_chunk(Constr, Chunk) ->
|
||||
Ret | no_return() when
|
||||
Constr :: yamerl_parser:yamerl_parser(),
|
||||
Chunk :: unicode_binary(),
|
||||
Ret :: {continue, New_Constr},
|
||||
New_Constr :: yamerl_parser:yamerl_parser().
|
||||
Ret | no_return() when
|
||||
Constr :: yamerl_parser:yamerl_parser(),
|
||||
Chunk :: unicode_binary(),
|
||||
Ret :: {continue, New_Constr},
|
||||
New_Constr :: yamerl_parser:yamerl_parser().
|
||||
|
||||
next_chunk(Constr, Chunk) ->
|
||||
next_chunk(Constr, Chunk, false).
|
||||
next_chunk(Constr, Chunk, false).
|
||||
|
||||
%% @doc Feeds the constructor with the next chunk from the YAML stream.
|
||||
%%
|
||||
%% `Constr' is the constructor state returned by a previous call
|
||||
%% to {@link new/1}, {@link new/2}, {@link next_chunk/2} or {@link
|
||||
%% next_chunk/3}.
|
||||
%%
|
||||
%% `Chunk' must be an Erlang binary using the UTF-8, UTF-16 or UTF-32
|
||||
%% Unicode encoding. A leading BOM character in the first chunk is used
|
||||
%% to determine the encoding and endianness. If no BOM is present, UTF-8
|
||||
%% is assumed.
|
||||
%%
|
||||
%% `EOS' indicates the constructor if this is the last chunk from the
|
||||
%% stream.
|
||||
%%
|
||||
%% If this is not the last chunk (`EOS = false'), it returns `{continue,
|
||||
%% New_Constr}' where `New_Constr' is an updated state which replaces
|
||||
%% `Constr'. The new state is to be passed to future calls to {@link
|
||||
%% next_chunk/2}, {@link next_chunk/3} or {@link last_chunk/2}.
|
||||
%%
|
||||
%% If this is the last chunk (`EOS = true'), it returns a list of YAML
|
||||
%% documents. Documents are made of simple builtin Erlang types if the
|
||||
%% detailed construction mode is disabled, or records if the detailed
|
||||
%% construction mode is enabled (`{detailed_constr, boolean()}' passed
|
||||
%% as an option; default is `false').
|
||||
%%
|
||||
%% It throws an exception if there is a parsing or construction error.
|
||||
|
||||
-spec next_chunk(Constr, Chunk, false) ->
|
||||
Ret | no_return() when
|
||||
@ -148,6 +320,8 @@ next_chunk(Constr, Chunk, EOS) ->
|
||||
true -> Ret
|
||||
end.
|
||||
|
||||
%% @equiv next_chunk(Constr, Chunk, true)
|
||||
|
||||
-spec last_chunk(Constr, Chunk) ->
|
||||
Result | no_return() when
|
||||
Constr :: yamerl_parser:yamerl_parser(),
|
||||
@ -179,6 +353,8 @@ get_docs(Constr) ->
|
||||
%% Public API: common stream sources.
|
||||
%% -------------------------------------------------------------------
|
||||
|
||||
%% @equiv string(String, [])
|
||||
|
||||
-spec string(String) ->
|
||||
Result | no_return() when
|
||||
String :: unicode_data(),
|
||||
@ -189,6 +365,89 @@ get_docs(Constr) ->
|
||||
string(String) ->
|
||||
string(String, []).
|
||||
|
||||
%% @doc Constructs a YAML document from an in-memory YAML string.
|
||||
%%
|
||||
%% `String' must be an Erlang list or binary containing one or more YAML
|
||||
%% documents. If it is a binary, it must be encoded using UTF-8, UTF-16
|
||||
%% or UTF-32. A leading BOM character is used to determine the encoding
|
||||
%% and endianness. If no BOM is present, UTF-8 is assumed.
|
||||
%%
|
||||
%% `Options' is a list of options for the parser and the constructor.
|
||||
%% See {@link new/2} for valid options.
|
||||
%%
|
||||
%% It returns a list of YAML documents. See {@link next_chunk/3} for
|
||||
%% more details about the returned documents.
|
||||
%%
|
||||
%% It throws an exception if there is a parsing or construction error.
|
||||
%%
|
||||
%% <strong>Example: parse an Erlang list</strong>
|
||||
%% ```
|
||||
%% yamerl_constr:string("This is a string").
|
||||
%% '''
|
||||
%%
|
||||
%% <strong>Example: parse an UTF-8-encoded Erlang binary</strong>
|
||||
%% ```
|
||||
%% yamerl_constr:string(<<50,32,226,130,172>>). % The string "2 €" encoded in UTF-8.
|
||||
%% '''
|
||||
%%
|
||||
%% <strong>Example: parse a string in simple mode</strong>
|
||||
%% ```
|
||||
%% yamerl_constr:string("Hello!").
|
||||
%% '''
|
||||
%%
|
||||
%% It returns:
|
||||
%% ```
|
||||
%% % List of documents; here, only one.
|
||||
%% [
|
||||
%% % Document root node: a string.
|
||||
%% "Hello!"
|
||||
%% ].
|
||||
%% '''
|
||||
%%
|
||||
%% <strong>Example: parse a string in detailed mode</strong>
|
||||
%% ```
|
||||
%% yamerl_constr:string("Hello!", [{detailed_constr, true}]).
|
||||
%% '''
|
||||
%%
|
||||
%% It returns:
|
||||
%% ```
|
||||
%% % List of documents; here, only one.
|
||||
%% [
|
||||
%% % Document #1.
|
||||
%% {yamerl_doc,
|
||||
%% % Document root node: a string.
|
||||
%% {yamerl_str, yamerl_node_str, "tag:yaml.org,2002:str",
|
||||
%% [{line, 1}, {column, 1}], % Node location in the original string.
|
||||
%% "Hello!" % String value.
|
||||
%% }
|
||||
%% }
|
||||
%% ].
|
||||
%% '''
|
||||
%%
|
||||
%% <strong>Example: parse an invalid document</strong>
|
||||
%% ```
|
||||
%% yamerl_constr:string(<<"'Oh-oh...">>). % Unfinished single-quoted scalar.
|
||||
%% '''
|
||||
%%
|
||||
%% It throws:
|
||||
%% ```
|
||||
%% {yamerl_exception,
|
||||
%% % List of warnings and errors; here, one fatal error.
|
||||
%% [
|
||||
%% % Error #1.
|
||||
%% {yamerl_parsing_error, error,
|
||||
%% "Unexpected end-of-stream while parsing flow scalar", % Human-readable message.
|
||||
%% 1, 10, % Error location.
|
||||
%% unexpected_eos,
|
||||
%% {yamerl_scalar, 1, 1, {yamerl_tag, 1, 1, {non_specific, "!"}}, % Token being parsed.
|
||||
%% flow, single_quoted,
|
||||
%% "Oh-oh..."},
|
||||
%% []
|
||||
%% }
|
||||
%% ]
|
||||
%% }.
|
||||
%% '''
|
||||
|
||||
-spec string(String, Options) ->
|
||||
Result | no_return() when
|
||||
String :: unicode_data(),
|
||||
@ -211,9 +470,28 @@ string(String, Options) ->
|
||||
| [yamerl_simple_doc()]
|
||||
| term().
|
||||
|
||||
%% @equiv file(Filename, [])
|
||||
|
||||
file(Filename) ->
|
||||
file(Filename, []).
|
||||
|
||||
%% @doc Constructs a YAML document from a regular file.
|
||||
%%
|
||||
%% `Filename' must be a string indicating the filename. The file must
|
||||
%% contain one or more YAML documents. The file must be encoded using
|
||||
%% UTF-8, UTF-16 or UTF-32. A leading BOM character is used to determine
|
||||
%% the encoding and endianness. If no BOM is present, UTF-8 is assumed.
|
||||
%%
|
||||
%% `Options' is a list of options for the parser and the constructor.
|
||||
%% See {@link new/2} for valid options.
|
||||
%%
|
||||
%% It returns a list of YAML documents. See {@link next_chunk/3} for
|
||||
%% more details about the returned documents.
|
||||
%%
|
||||
%% It throws an exception if there is a parsing or construction error.
|
||||
%%
|
||||
%% See {@link string/2} for some examples.
|
||||
|
||||
-spec file(Filename, Options) ->
|
||||
Result | no_return() when
|
||||
Filename :: string(),
|
||||
@ -233,6 +511,13 @@ file(Filename, Options) ->
|
||||
%% Presentation details.
|
||||
%% -------------------------------------------------------------------
|
||||
|
||||
%% @doc Returns presentation informations in the stream for the given
|
||||
%% node.
|
||||
%%
|
||||
%% This only makes sense when the detailed construction mode is enabled
|
||||
%% (ie. `{detailed_constr, true}' was passed as an option to {@link
|
||||
%% new/2}, {@link file/2} or {@link string/2}).
|
||||
|
||||
get_pres_details(Token) ->
|
||||
Line = ?TOKEN_LINE(Token),
|
||||
Column = ?TOKEN_COLUMN(Token),
|
||||
@ -242,12 +527,24 @@ get_pres_details(Token) ->
|
||||
%% Node informations.
|
||||
%% -------------------------------------------------------------------
|
||||
|
||||
%% @doc Returns the line number in the stream for the given node.
|
||||
%%
|
||||
%% This only makes sense when the detailed construction mode is enabled
|
||||
%% (ie. `{detailed_constr, true}' was passed as an option to {@link
|
||||
%% new/2}, {@link file/2} or {@link string/2}).
|
||||
|
||||
node_line(Node) ->
|
||||
case node_pres(Node) of
|
||||
undefined -> undefined;
|
||||
Pres -> proplists:get_value(line, Pres)
|
||||
end.
|
||||
|
||||
%% @doc Returns the column number in the stream for the given node.
|
||||
%%
|
||||
%% This only makes sense when the detailed construction mode is enabled
|
||||
%% (ie. `{detailed_constr, true}' was passed as an option to {@link
|
||||
%% new/2}, {@link file/2} or {@link string/2}).
|
||||
|
||||
node_column(Node) ->
|
||||
case node_pres(Node) of
|
||||
undefined -> undefined;
|
||||
@ -553,6 +850,8 @@ filter_options2([], _, _, Constr_Options, Parser_Options, Ext_Options) ->
|
||||
lists:reverse(Ext_Options)
|
||||
}.
|
||||
|
||||
%% @private
|
||||
|
||||
option_names() ->
|
||||
[
|
||||
node_mods,
|
||||
|
@ -24,6 +24,8 @@
|
||||
% OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
% SUCH DAMAGE.
|
||||
|
||||
%% @private
|
||||
|
||||
-module(yamerl_errors).
|
||||
|
||||
-include("yamerl_errors.hrl").
|
||||
|
@ -24,6 +24,8 @@
|
||||
% OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
% SUCH DAMAGE.
|
||||
|
||||
%% @private
|
||||
|
||||
-module(yamerl_node_bool).
|
||||
|
||||
-include("yamerl_tokens.hrl").
|
||||
|
@ -24,6 +24,8 @@
|
||||
% OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
% SUCH DAMAGE.
|
||||
|
||||
%% @private
|
||||
|
||||
-module(yamerl_node_bool_ext).
|
||||
|
||||
-include("yamerl_tokens.hrl").
|
||||
|
@ -24,6 +24,8 @@
|
||||
% OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
% SUCH DAMAGE.
|
||||
|
||||
%% @private
|
||||
|
||||
-module(yamerl_node_bool_json).
|
||||
|
||||
-include("yamerl_tokens.hrl").
|
||||
|
@ -24,6 +24,8 @@
|
||||
% OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
% SUCH DAMAGE.
|
||||
|
||||
%% @private
|
||||
|
||||
-module(yamerl_node_erlang_atom).
|
||||
|
||||
-include("yamerl_errors.hrl").
|
||||
|
@ -24,6 +24,8 @@
|
||||
% OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
% SUCH DAMAGE.
|
||||
|
||||
%% @private
|
||||
|
||||
-module(yamerl_node_erlang_fun).
|
||||
|
||||
-include("yamerl_errors.hrl").
|
||||
|
@ -24,6 +24,8 @@
|
||||
% OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
% SUCH DAMAGE.
|
||||
|
||||
%% @private
|
||||
|
||||
-module(yamerl_node_float).
|
||||
|
||||
-include("yamerl_errors.hrl").
|
||||
|
@ -24,6 +24,8 @@
|
||||
% OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
% SUCH DAMAGE.
|
||||
|
||||
%% @private
|
||||
|
||||
-module(yamerl_node_float_ext).
|
||||
|
||||
-include("yamerl_errors.hrl").
|
||||
|
@ -24,6 +24,8 @@
|
||||
% OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
% SUCH DAMAGE.
|
||||
|
||||
%% @private
|
||||
|
||||
-module(yamerl_node_float_json).
|
||||
|
||||
-include("yamerl_errors.hrl").
|
||||
|
@ -24,6 +24,8 @@
|
||||
% OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
% SUCH DAMAGE.
|
||||
|
||||
%% @private
|
||||
|
||||
-module(yamerl_node_int).
|
||||
|
||||
-include("yamerl_errors.hrl").
|
||||
|
@ -24,6 +24,8 @@
|
||||
% OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
% SUCH DAMAGE.
|
||||
|
||||
%% @private
|
||||
|
||||
-module(yamerl_node_int_ext).
|
||||
|
||||
-include("yamerl_errors.hrl").
|
||||
|
@ -24,6 +24,8 @@
|
||||
% OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
% SUCH DAMAGE.
|
||||
|
||||
%% @private
|
||||
|
||||
-module(yamerl_node_int_json).
|
||||
|
||||
-include("yamerl_errors.hrl").
|
||||
|
@ -24,6 +24,8 @@
|
||||
% OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
% SUCH DAMAGE.
|
||||
|
||||
%% @private
|
||||
|
||||
-module(yamerl_node_ipaddr).
|
||||
|
||||
-include("yamerl_errors.hrl").
|
||||
|
@ -24,6 +24,8 @@
|
||||
% OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
% SUCH DAMAGE.
|
||||
|
||||
%% @private
|
||||
|
||||
-module(yamerl_node_map).
|
||||
|
||||
-include("yamerl_errors.hrl").
|
||||
|
@ -24,6 +24,8 @@
|
||||
% OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
% SUCH DAMAGE.
|
||||
|
||||
%% @private
|
||||
|
||||
-module(yamerl_node_null).
|
||||
|
||||
-include("yamerl_tokens.hrl").
|
||||
|
@ -24,6 +24,8 @@
|
||||
% OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
% SUCH DAMAGE.
|
||||
|
||||
%% @private
|
||||
|
||||
-module(yamerl_node_null_json).
|
||||
|
||||
-include("yamerl_tokens.hrl").
|
||||
|
@ -24,6 +24,8 @@
|
||||
% OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
% SUCH DAMAGE.
|
||||
|
||||
%% @private
|
||||
|
||||
-module(yamerl_node_seq).
|
||||
|
||||
-include("yamerl_errors.hrl").
|
||||
|
@ -24,6 +24,8 @@
|
||||
% OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
% SUCH DAMAGE.
|
||||
|
||||
%% @private
|
||||
|
||||
-module(yamerl_node_size).
|
||||
|
||||
-include("yamerl_errors.hrl").
|
||||
|
@ -24,6 +24,8 @@
|
||||
% OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
% SUCH DAMAGE.
|
||||
|
||||
%% @private
|
||||
|
||||
-module(yamerl_node_str).
|
||||
|
||||
-include("yamerl_errors.hrl").
|
||||
|
@ -24,6 +24,8 @@
|
||||
% OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
% SUCH DAMAGE.
|
||||
|
||||
%% @private
|
||||
|
||||
-module(yamerl_node_str_json).
|
||||
|
||||
-include("yamerl_errors.hrl").
|
||||
|
@ -24,6 +24,8 @@
|
||||
% OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
% SUCH DAMAGE.
|
||||
|
||||
%% @private
|
||||
|
||||
-module(yamerl_node_timestamp).
|
||||
|
||||
-include("yamerl_errors.hrl").
|
||||
|
@ -24,6 +24,16 @@
|
||||
% OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
% SUCH DAMAGE.
|
||||
|
||||
%% @author Jean-Sébastien Pédron <jean-sebastien.pedron@dumbbell.fr>
|
||||
%% @copyright
|
||||
%% 2012-2014 Yakaz,
|
||||
%% 2016 Jean-Sébastien Pédron <jean-sebastien.pedron@dumbbell.fr>
|
||||
%%
|
||||
%% @doc {@module} implements a YAML parser. It is not meant to be used
|
||||
%% directly. Instead, you should use {@link yamerl_constr}.
|
||||
%%
|
||||
%% The `yamerl' application must be started to use the parser.
|
||||
|
||||
-module(yamerl_parser).
|
||||
|
||||
-include("yamerl_errors.hrl").
|
||||
@ -68,32 +78,32 @@
|
||||
%% -------------------------------------------------------------------
|
||||
|
||||
-record(directive_ctx, {
|
||||
line :: position(),
|
||||
col :: position(),
|
||||
line = 1 :: position(),
|
||||
col = 1 :: position(),
|
||||
name = "" :: string()
|
||||
}).
|
||||
|
||||
-record(yaml_directive_ctx, {
|
||||
line :: position(),
|
||||
col :: position(),
|
||||
major :: non_neg_integer(),
|
||||
minor :: non_neg_integer()
|
||||
line = 1 :: position(),
|
||||
col = 1 :: position(),
|
||||
major :: non_neg_integer() | undefined,
|
||||
minor :: non_neg_integer() | undefined
|
||||
}).
|
||||
|
||||
-record(tag_directive_ctx, {
|
||||
line :: position(),
|
||||
col :: position(),
|
||||
handle :: tag_handle() | [] | undefined,
|
||||
prefix :: tag_prefix() | [] | undefined
|
||||
line = 1 :: position(),
|
||||
col = 1 :: position(),
|
||||
handle :: tag_handle() | [] | undefined,
|
||||
prefix :: tag_prefix() | [] | undefined
|
||||
}).
|
||||
|
||||
-record(reserved_directive_ctx, {
|
||||
line :: position(),
|
||||
col :: position(),
|
||||
name :: string(),
|
||||
current :: string(),
|
||||
args = [] :: [string()],
|
||||
args_count = 0 :: non_neg_integer()
|
||||
line = 1 :: position(),
|
||||
col = 1 :: position(),
|
||||
name = "" :: string(),
|
||||
current :: string() | undefined,
|
||||
args = [] :: [string()],
|
||||
args_count = 0 :: non_neg_integer()
|
||||
}).
|
||||
|
||||
-type whitespace() :: [9 | 10 | 32].
|
||||
@ -276,6 +286,8 @@
|
||||
%% Public API: chunked stream scanning.
|
||||
%% -------------------------------------------------------------------
|
||||
|
||||
%% @equiv new(Source, [])
|
||||
|
||||
-spec new(Source) ->
|
||||
Parser | no_return() when
|
||||
Source :: term(),
|
||||
@ -284,6 +296,8 @@
|
||||
new(Source) ->
|
||||
new(Source, []).
|
||||
|
||||
%% @doc Creates and returns a new YAML parser state.
|
||||
|
||||
-spec new(Source, Options) ->
|
||||
Parser | no_return() when
|
||||
Source :: term(),
|
||||
@ -300,6 +314,8 @@ new(Source, Options) ->
|
||||
token_fun = proplists:get_value(token_fun, Options0, acc)
|
||||
}.
|
||||
|
||||
%% @equiv next_chunk(Parser, Chunk, false)
|
||||
|
||||
-spec next_chunk(Parser, Chunk) ->
|
||||
Ret | no_return() when
|
||||
Parser :: yamerl_parser(),
|
||||
@ -310,6 +326,8 @@ new(Source, Options) ->
|
||||
next_chunk(Parser, Chunk) ->
|
||||
next_chunk(Parser, Chunk, false).
|
||||
|
||||
%% @doc Feeds the parser with the next chunk from the YAML stream.
|
||||
|
||||
-spec next_chunk(Parser, Chunk, Last_Chunk) ->
|
||||
Ret | no_return() when
|
||||
Parser :: yamerl_parser(),
|
||||
@ -331,6 +349,8 @@ next_chunk(#yamerl_parser{raw_data = Data} = Parser, Chunk, EOS) ->
|
||||
},
|
||||
decode_unicode(Parser1).
|
||||
|
||||
%% @equiv next_chunk(Parser, Chunk, true)
|
||||
|
||||
-spec last_chunk(Parser, Chunk) ->
|
||||
Ret | no_return() when
|
||||
Parser :: yamerl_parser(),
|
||||
@ -345,6 +365,8 @@ last_chunk(Parser, Chunk) ->
|
||||
%% Public API: common stream sources.
|
||||
%% -------------------------------------------------------------------
|
||||
|
||||
%% @equiv string(String, [])
|
||||
|
||||
-spec string(String) ->
|
||||
Parser | no_return() when
|
||||
String :: unicode_data(),
|
||||
@ -353,6 +375,8 @@ last_chunk(Parser, Chunk) ->
|
||||
string(String) ->
|
||||
string(String, []).
|
||||
|
||||
%% @doc Parses a YAML document from an in-memory YAML string.
|
||||
|
||||
-spec string(String, Options) ->
|
||||
Parser | no_return() when
|
||||
String :: unicode_data(),
|
||||
@ -365,6 +389,8 @@ string(String, Options) when is_binary(String) ->
|
||||
string(String, Options) when is_list(String) ->
|
||||
string(unicode:characters_to_binary(String), Options).
|
||||
|
||||
%% @equiv file(Filename, [])
|
||||
|
||||
-spec file(Filename) ->
|
||||
Parser | no_return() when
|
||||
Filename :: string(),
|
||||
@ -373,6 +399,8 @@ string(String, Options) when is_list(String) ->
|
||||
file(Filename) ->
|
||||
file(Filename, []).
|
||||
|
||||
%% @doc Parses a YAML document from a regular file.
|
||||
|
||||
-spec file(Filename, Options) ->
|
||||
Parser | no_return() when
|
||||
Filename :: string(),
|
||||
@ -440,9 +468,13 @@ file2(#yamerl_parser{source = {file, Filename}} = Parser, FD, Blocksize) ->
|
||||
%% Public API: get/set the token function.
|
||||
%% -------------------------------------------------------------------
|
||||
|
||||
%% @doc Returns the constructor callback function
|
||||
|
||||
get_token_fun(#yamerl_parser{token_fun = Fun}) ->
|
||||
Fun.
|
||||
|
||||
%% @doc Sets the constructor callback function
|
||||
|
||||
set_token_fun(Parser, Fun) when is_function(Fun, 1) ->
|
||||
Parser#yamerl_parser{token_fun = Fun}.
|
||||
|
||||
@ -4203,6 +4235,8 @@ setup_default_tags(#yamerl_parser{options = Options} = Parser) ->
|
||||
%% Internal functions.
|
||||
%% -------------------------------------------------------------------
|
||||
|
||||
%% @private
|
||||
|
||||
option_names() ->
|
||||
[
|
||||
default_tags,
|
||||
|
@ -24,6 +24,8 @@
|
||||
% OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
% SUCH DAMAGE.
|
||||
|
||||
%% @private
|
||||
|
||||
-module(yamerl_sup).
|
||||
|
||||
-behaviour(supervisor).
|
||||
|
@ -24,6 +24,16 @@
|
||||
% OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
% SUCH DAMAGE.
|
||||
|
||||
%% @author Jean-Sébastien Pédron <jean-sebastien.pedron@dumbbell.fr>
|
||||
%% @copyright
|
||||
%% 2012-2014 Yakaz,
|
||||
%% 2016 Jean-Sébastien Pédron <jean-sebastien.pedron@dumbbell.fr>
|
||||
%%
|
||||
%% @doc {@module} implements the <em>yamerl</em> API above {@link
|
||||
%% yamerl_constr}.
|
||||
%%
|
||||
%% See <em>yamler</em> documentation: [https://github.com/goertzenator/yamler].
|
||||
|
||||
-module(yamerl_yamler_compat).
|
||||
|
||||
-include("yamerl_errors.hrl").
|
||||
@ -50,6 +60,8 @@
|
||||
%% Public API.
|
||||
%% -------------------------------------------------------------------
|
||||
|
||||
%% @equiv load(String, [])
|
||||
|
||||
-spec load(String) ->
|
||||
Result | Error when
|
||||
String :: binary(),
|
||||
@ -60,6 +72,10 @@
|
||||
load(String) ->
|
||||
load(String, []).
|
||||
|
||||
%% @doc Constructs a YAML document from an in-memory string.
|
||||
%%
|
||||
%% The `yamerl' application must be started to use this wrapper.
|
||||
|
||||
-spec load(String, Options) ->
|
||||
Result | Error when
|
||||
String :: binary(),
|
||||
@ -78,6 +94,8 @@ load(String, Options) ->
|
||||
format_error(Error)
|
||||
end.
|
||||
|
||||
%% @equiv load_file(Filename, [])
|
||||
|
||||
-spec load_file(Filename) ->
|
||||
Result | Error when
|
||||
Filename :: string(),
|
||||
@ -88,6 +106,8 @@ load(String, Options) ->
|
||||
load_file(Filename) ->
|
||||
load_file(Filename, []).
|
||||
|
||||
%% @doc Constructs a YAML document from a regular file.
|
||||
|
||||
-spec load_file(Filename, Options) ->
|
||||
Result | Error when
|
||||
Filename :: string(),
|
||||
@ -106,6 +126,8 @@ load_file(Filename, Options) ->
|
||||
format_error(Error)
|
||||
end.
|
||||
|
||||
%% @private
|
||||
|
||||
-spec convert_options(Options) ->
|
||||
Converted when
|
||||
Options :: [yamler_option()],
|
||||
@ -118,6 +140,8 @@ load_file(Filename, Options) ->
|
||||
convert_options(Options) ->
|
||||
convert_options(Options, []).
|
||||
|
||||
%% @private
|
||||
|
||||
convert_options([{schema, yaml_schema_failsafe} | Rest], Converted) ->
|
||||
Converted1 = [
|
||||
{schema, failsafe}
|
||||
|
49
test/construction/alias.erl
Normal file
49
test/construction/alias.erl
Normal file
@ -0,0 +1,49 @@
|
||||
-module(alias).
|
||||
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
|
||||
-define(FILENAME, "test/construction/" ?MODULE_STRING ".yaml").
|
||||
|
||||
setup() ->
|
||||
application:start(yamerl).
|
||||
|
||||
simple_test_() ->
|
||||
{setup,
|
||||
fun setup/0,
|
||||
[
|
||||
?_assertMatch(
|
||||
[
|
||||
[
|
||||
"Duplicate",
|
||||
"Duplicate"
|
||||
]
|
||||
],
|
||||
yamerl_constr:file(?FILENAME, [{detailed_constr, false}])
|
||||
)
|
||||
]
|
||||
}.
|
||||
|
||||
detailed_test_() ->
|
||||
{setup,
|
||||
fun setup/0,
|
||||
[
|
||||
?_assertMatch(
|
||||
[
|
||||
{yamerl_doc,
|
||||
{yamerl_seq,yamerl_node_seq, "tag:yaml.org,2002:seq",
|
||||
[{line,1},{column,1}],
|
||||
[
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,1},{column,11}],
|
||||
"Duplicate"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,1},{column,11}],
|
||||
"Duplicate"}
|
||||
],
|
||||
2}
|
||||
}
|
||||
],
|
||||
yamerl_constr:file(?FILENAME, [{detailed_constr, true}])
|
||||
)
|
||||
]
|
||||
}.
|
377
test/construction/bool.erl
Normal file
377
test/construction/bool.erl
Normal file
@ -0,0 +1,377 @@
|
||||
-module(bool).
|
||||
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
|
||||
-define(FILENAME, "test/construction/" ?MODULE_STRING ".yaml").
|
||||
|
||||
setup() ->
|
||||
application:start(yamerl).
|
||||
|
||||
schema_failsafe_simple_test_() ->
|
||||
{setup,
|
||||
fun setup/0,
|
||||
[
|
||||
?_assertMatch(
|
||||
[
|
||||
[
|
||||
"true", "True", "TRUE",
|
||||
"y", "Y",
|
||||
"yes", "Yes", "YES",
|
||||
"on", "On", "ON",
|
||||
"false", "False", "FALSE",
|
||||
"n", "N",
|
||||
"no", "No", "NO",
|
||||
"off", "Off", "OFF",
|
||||
"Not a bool"
|
||||
]
|
||||
],
|
||||
yamerl_constr:file(?FILENAME,
|
||||
[{detailed_constr, false}, {schema, failsafe}])
|
||||
)
|
||||
]
|
||||
}.
|
||||
|
||||
schema_json_simple_test_() ->
|
||||
{setup,
|
||||
fun setup/0,
|
||||
[
|
||||
?_assertThrow(
|
||||
{yamerl_exception, [
|
||||
{yamerl_parsing_error,error, "Invalid string", 2, 3, not_a_string,
|
||||
{yamerl_scalar, 2, 3,
|
||||
{yamerl_tag, 2, 3, {non_specific, "?"}},
|
||||
flow, plain, "True"},
|
||||
[]}]},
|
||||
yamerl_constr:file(?FILENAME,
|
||||
[{detailed_constr, false}, {schema, json}])
|
||||
)
|
||||
]
|
||||
}.
|
||||
|
||||
schema_core_simple_test_() ->
|
||||
{setup,
|
||||
fun setup/0,
|
||||
[
|
||||
?_assertMatch(
|
||||
[
|
||||
[
|
||||
true, true, true,
|
||||
"y", "Y",
|
||||
"yes", "Yes", "YES",
|
||||
"on", "On", "ON",
|
||||
false, false, false,
|
||||
"n", "N",
|
||||
"no", "No", "NO",
|
||||
"off", "Off", "OFF",
|
||||
"Not a bool"
|
||||
]
|
||||
],
|
||||
yamerl_constr:file(?FILENAME,
|
||||
[{detailed_constr, false}, {schema, core}])
|
||||
)
|
||||
]
|
||||
}.
|
||||
|
||||
schema_failsafe_bool_ext_simple_test_() ->
|
||||
{setup,
|
||||
fun setup/0,
|
||||
[
|
||||
?_assertMatch(
|
||||
[
|
||||
[
|
||||
true, true, true,
|
||||
true, true,
|
||||
true, true, true,
|
||||
true, true, true,
|
||||
false, false, false,
|
||||
false, false,
|
||||
false, false, false,
|
||||
false, false, false,
|
||||
"Not a bool"
|
||||
]
|
||||
],
|
||||
yamerl_constr:file(?FILENAME,
|
||||
[{detailed_constr, false}, {schema, failsafe},
|
||||
{node_mods, [yamerl_node_bool_ext]}])
|
||||
)
|
||||
]
|
||||
}.
|
||||
|
||||
schema_failsafe_detailed_test_() ->
|
||||
{setup,
|
||||
fun setup/0,
|
||||
[
|
||||
?_assertMatch(
|
||||
[
|
||||
{yamerl_doc,
|
||||
{yamerl_seq,yamerl_node_seq,"tag:yaml.org,2002:seq",
|
||||
[{line,1},{column,1}],
|
||||
[{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,1},{column,3}],
|
||||
"true"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,2},{column,3}],
|
||||
"True"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,3},{column,3}],
|
||||
"TRUE"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,4},{column,3}],
|
||||
"y"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,5},{column,3}],
|
||||
"Y"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,6},{column,3}],
|
||||
"yes"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,7},{column,3}],
|
||||
"Yes"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,8},{column,3}],
|
||||
"YES"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,9},{column,3}],
|
||||
"on"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,10},{column,3}],
|
||||
"On"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,11},{column,3}],
|
||||
"ON"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,13},{column,3}],
|
||||
"false"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,14},{column,3}],
|
||||
"False"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,15},{column,3}],
|
||||
"FALSE"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,16},{column,3}],
|
||||
"n"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,17},{column,3}],
|
||||
"N"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,18},{column,3}],
|
||||
"no"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,19},{column,3}],
|
||||
"No"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,20},{column,3}],
|
||||
"NO"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,21},{column,3}],
|
||||
"off"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,22},{column,3}],
|
||||
"Off"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,23},{column,3}],
|
||||
"OFF"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,25},{column,3}],
|
||||
"Not a bool"}],
|
||||
23}
|
||||
}
|
||||
],
|
||||
yamerl_constr:file(?FILENAME,
|
||||
[{detailed_constr, true}, {schema, failsafe}])
|
||||
)
|
||||
]
|
||||
}.
|
||||
|
||||
schema_json_detailed_test_() ->
|
||||
{setup,
|
||||
fun setup/0,
|
||||
[
|
||||
?_assertThrow(
|
||||
{yamerl_exception, [
|
||||
{yamerl_parsing_error,error, "Invalid string", 2, 3, not_a_string,
|
||||
{yamerl_scalar, 2, 3,
|
||||
{yamerl_tag, 2, 3, {non_specific, "?"}},
|
||||
flow, plain, "True"},
|
||||
[]}]},
|
||||
yamerl_constr:file(?FILENAME,
|
||||
[{detailed_constr, true}, {schema, json}])
|
||||
)
|
||||
]
|
||||
}.
|
||||
|
||||
schema_core_detailed_test_() ->
|
||||
{setup,
|
||||
fun setup/0,
|
||||
[
|
||||
?_assertMatch(
|
||||
[
|
||||
{yamerl_doc,
|
||||
{yamerl_seq,yamerl_node_seq,"tag:yaml.org,2002:seq",
|
||||
[{line,1},{column,1}],
|
||||
[{yamerl_bool,yamerl_node_bool,"tag:yaml.org,2002:bool",
|
||||
[{line,1},{column,3}],
|
||||
true},
|
||||
{yamerl_bool,yamerl_node_bool,"tag:yaml.org,2002:bool",
|
||||
[{line,2},{column,3}],
|
||||
true},
|
||||
{yamerl_bool,yamerl_node_bool,"tag:yaml.org,2002:bool",
|
||||
[{line,3},{column,3}],
|
||||
true},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,4},{column,3}],
|
||||
"y"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,5},{column,3}],
|
||||
"Y"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,6},{column,3}],
|
||||
"yes"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,7},{column,3}],
|
||||
"Yes"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,8},{column,3}],
|
||||
"YES"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,9},{column,3}],
|
||||
"on"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,10},{column,3}],
|
||||
"On"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,11},{column,3}],
|
||||
"ON"},
|
||||
{yamerl_bool,yamerl_node_bool,"tag:yaml.org,2002:bool",
|
||||
[{line,13},{column,3}],
|
||||
false},
|
||||
{yamerl_bool,yamerl_node_bool,"tag:yaml.org,2002:bool",
|
||||
[{line,14},{column,3}],
|
||||
false},
|
||||
{yamerl_bool,yamerl_node_bool,"tag:yaml.org,2002:bool",
|
||||
[{line,15},{column,3}],
|
||||
false},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,16},{column,3}],
|
||||
"n"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,17},{column,3}],
|
||||
"N"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,18},{column,3}],
|
||||
"no"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,19},{column,3}],
|
||||
"No"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,20},{column,3}],
|
||||
"NO"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,21},{column,3}],
|
||||
"off"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,22},{column,3}],
|
||||
"Off"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,23},{column,3}],
|
||||
"OFF"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,25},{column,3}],
|
||||
"Not a bool"}],
|
||||
23}
|
||||
}
|
||||
],
|
||||
yamerl_constr:file(?FILENAME,
|
||||
[{detailed_constr, true}, {schema, core}])
|
||||
)
|
||||
]
|
||||
}.
|
||||
|
||||
schema_failsafe_bool_ext_detailed_test_() ->
|
||||
{setup,
|
||||
fun setup/0,
|
||||
[
|
||||
?_assertMatch(
|
||||
[
|
||||
{yamerl_doc,
|
||||
{yamerl_seq,yamerl_node_seq,"tag:yaml.org,2002:seq",
|
||||
[{line,1},{column,1}],
|
||||
[{yamerl_bool,yamerl_node_bool_ext,"tag:yaml.org,2002:bool",
|
||||
[{line,1},{column,3}],
|
||||
true},
|
||||
{yamerl_bool,yamerl_node_bool_ext,"tag:yaml.org,2002:bool",
|
||||
[{line,2},{column,3}],
|
||||
true},
|
||||
{yamerl_bool,yamerl_node_bool_ext,"tag:yaml.org,2002:bool",
|
||||
[{line,3},{column,3}],
|
||||
true},
|
||||
{yamerl_bool,yamerl_node_bool_ext,"tag:yaml.org,2002:bool",
|
||||
[{line,4},{column,3}],
|
||||
true},
|
||||
{yamerl_bool,yamerl_node_bool_ext,"tag:yaml.org,2002:bool",
|
||||
[{line,5},{column,3}],
|
||||
true},
|
||||
{yamerl_bool,yamerl_node_bool_ext,"tag:yaml.org,2002:bool",
|
||||
[{line,6},{column,3}],
|
||||
true},
|
||||
{yamerl_bool,yamerl_node_bool_ext,"tag:yaml.org,2002:bool",
|
||||
[{line,7},{column,3}],
|
||||
true},
|
||||
{yamerl_bool,yamerl_node_bool_ext,"tag:yaml.org,2002:bool",
|
||||
[{line,8},{column,3}],
|
||||
true},
|
||||
{yamerl_bool,yamerl_node_bool_ext,"tag:yaml.org,2002:bool",
|
||||
[{line,9},{column,3}],
|
||||
true},
|
||||
{yamerl_bool,yamerl_node_bool_ext,"tag:yaml.org,2002:bool",
|
||||
[{line,10},{column,3}],
|
||||
true},
|
||||
{yamerl_bool,yamerl_node_bool_ext,"tag:yaml.org,2002:bool",
|
||||
[{line,11},{column,3}],
|
||||
true},
|
||||
{yamerl_bool,yamerl_node_bool_ext,"tag:yaml.org,2002:bool",
|
||||
[{line,13},{column,3}],
|
||||
false},
|
||||
{yamerl_bool,yamerl_node_bool_ext,"tag:yaml.org,2002:bool",
|
||||
[{line,14},{column,3}],
|
||||
false},
|
||||
{yamerl_bool,yamerl_node_bool_ext,"tag:yaml.org,2002:bool",
|
||||
[{line,15},{column,3}],
|
||||
false},
|
||||
{yamerl_bool,yamerl_node_bool_ext,"tag:yaml.org,2002:bool",
|
||||
[{line,16},{column,3}],
|
||||
false},
|
||||
{yamerl_bool,yamerl_node_bool_ext,"tag:yaml.org,2002:bool",
|
||||
[{line,17},{column,3}],
|
||||
false},
|
||||
{yamerl_bool,yamerl_node_bool_ext,"tag:yaml.org,2002:bool",
|
||||
[{line,18},{column,3}],
|
||||
false},
|
||||
{yamerl_bool,yamerl_node_bool_ext,"tag:yaml.org,2002:bool",
|
||||
[{line,19},{column,3}],
|
||||
false},
|
||||
{yamerl_bool,yamerl_node_bool_ext,"tag:yaml.org,2002:bool",
|
||||
[{line,20},{column,3}],
|
||||
false},
|
||||
{yamerl_bool,yamerl_node_bool_ext,"tag:yaml.org,2002:bool",
|
||||
[{line,21},{column,3}],
|
||||
false},
|
||||
{yamerl_bool,yamerl_node_bool_ext,"tag:yaml.org,2002:bool",
|
||||
[{line,22},{column,3}],
|
||||
false},
|
||||
{yamerl_bool,yamerl_node_bool_ext,"tag:yaml.org,2002:bool",
|
||||
[{line,23},{column,3}],
|
||||
false},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,25},{column,3}],
|
||||
"Not a bool"}],
|
||||
23}
|
||||
}
|
||||
],
|
||||
yamerl_constr:file(?FILENAME,
|
||||
[{detailed_constr, true}, {schema, failsafe},
|
||||
{node_mods, [yamerl_node_bool_ext]}])
|
||||
)
|
||||
]
|
||||
}.
|
51
test/construction/bool_json.erl
Normal file
51
test/construction/bool_json.erl
Normal file
@ -0,0 +1,51 @@
|
||||
-module(bool_json).
|
||||
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
|
||||
-define(FILENAME, "test/construction/" ?MODULE_STRING ".yaml").
|
||||
|
||||
setup() ->
|
||||
application:start(yamerl).
|
||||
|
||||
simple_test_() ->
|
||||
{setup,
|
||||
fun setup/0,
|
||||
[
|
||||
?_assertMatch(
|
||||
[
|
||||
[
|
||||
true,
|
||||
false
|
||||
]
|
||||
],
|
||||
yamerl_constr:file(?FILENAME,
|
||||
[{detailed_constr, false}, {schema, json}])
|
||||
)
|
||||
]
|
||||
}.
|
||||
|
||||
detailed_test_() ->
|
||||
{setup,
|
||||
fun setup/0,
|
||||
[
|
||||
?_assertMatch(
|
||||
[
|
||||
{yamerl_doc,
|
||||
{yamerl_seq,yamerl_node_seq,"tag:yaml.org,2002:seq",
|
||||
[{line,1},{column,1}],
|
||||
[{yamerl_bool,yamerl_node_bool_json,
|
||||
"tag:yaml.org,2002:bool",
|
||||
[{line,1},{column,3}],
|
||||
true},
|
||||
{yamerl_bool,yamerl_node_bool_json,
|
||||
"tag:yaml.org,2002:bool",
|
||||
[{line,2},{column,3}],
|
||||
false}],
|
||||
2}
|
||||
}
|
||||
],
|
||||
yamerl_constr:file(?FILENAME,
|
||||
[{detailed_constr, true}, {schema, json}])
|
||||
)
|
||||
]
|
||||
}.
|
30
test/construction/empty.erl
Normal file
30
test/construction/empty.erl
Normal file
@ -0,0 +1,30 @@
|
||||
-module(empty).
|
||||
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
|
||||
-define(FILENAME, "test/construction/" ?MODULE_STRING ".yaml").
|
||||
|
||||
setup() ->
|
||||
application:start(yamerl).
|
||||
|
||||
simple_test_() ->
|
||||
{setup,
|
||||
fun setup/0,
|
||||
[
|
||||
?_assertMatch(
|
||||
[],
|
||||
yamerl_constr:file(?FILENAME, [{detailed_constr, false}])
|
||||
)
|
||||
]
|
||||
}.
|
||||
|
||||
detailed_test_() ->
|
||||
{setup,
|
||||
fun setup/0,
|
||||
[
|
||||
?_assertMatch(
|
||||
[],
|
||||
yamerl_constr:file(?FILENAME, [{detailed_constr, true}])
|
||||
)
|
||||
]
|
||||
}.
|
147
test/construction/erlang_atom.erl
Normal file
147
test/construction/erlang_atom.erl
Normal file
@ -0,0 +1,147 @@
|
||||
-module(erlang_atom).
|
||||
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
|
||||
-define(FILENAME, "test/construction/" ?MODULE_STRING ".yaml").
|
||||
|
||||
setup() ->
|
||||
application:start(yamerl),
|
||||
yamerl_app:set_param(node_mods, [yamerl_node_erlang_atom]).
|
||||
|
||||
simple_test_() ->
|
||||
{setup,
|
||||
fun setup/0,
|
||||
[
|
||||
?_assertMatch(
|
||||
[
|
||||
[
|
||||
atom,
|
||||
'atom requiring quoting!',
|
||||
"atom",
|
||||
"node@domain",
|
||||
"not an atom",
|
||||
"NotAnAtom",
|
||||
"Not an atom",
|
||||
"Not an atom"
|
||||
]
|
||||
],
|
||||
yamerl_constr:file(?FILENAME, [{detailed_constr, false}])
|
||||
)
|
||||
]
|
||||
}.
|
||||
|
||||
autodetection_simple_test_() ->
|
||||
{setup,
|
||||
fun setup/0,
|
||||
[
|
||||
?_assertMatch(
|
||||
[
|
||||
[
|
||||
atom,
|
||||
'atom requiring quoting!',
|
||||
atom,
|
||||
node@domain,
|
||||
"not an atom",
|
||||
"NotAnAtom",
|
||||
"Not an atom",
|
||||
"Not an atom"
|
||||
]
|
||||
],
|
||||
yamerl_constr:file(?FILENAME, [
|
||||
{detailed_constr, false},
|
||||
{erlang_atom_autodetection, true}
|
||||
])
|
||||
)
|
||||
]
|
||||
}.
|
||||
|
||||
detailed_test_() ->
|
||||
{setup,
|
||||
fun setup/0,
|
||||
[
|
||||
?_assertMatch(
|
||||
[
|
||||
{yamerl_doc,
|
||||
{yamerl_seq,yamerl_node_seq,"tag:yaml.org,2002:seq",
|
||||
[{line,1},{column,1}],
|
||||
[
|
||||
{yamerl_erlang_atom,yamerl_node_erlang_atom,
|
||||
"tag:yamerl,2012:atom",
|
||||
[{line,1},{column,27}],
|
||||
atom},
|
||||
{yamerl_erlang_atom,yamerl_node_erlang_atom,
|
||||
"tag:yamerl,2012:atom",
|
||||
[{line,2},{column,27}],
|
||||
'atom requiring quoting!'},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,4},{column,3}],
|
||||
"atom"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,5},{column,3}],
|
||||
"node@domain"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,7},{column,3}],
|
||||
"not an atom"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,8},{column,3}],
|
||||
"NotAnAtom"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,9},{column,3}],
|
||||
"Not an atom"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,10},{column,3}],
|
||||
"Not an atom"}],
|
||||
8}}
|
||||
],
|
||||
yamerl_constr:file(?FILENAME, [{detailed_constr, true}])
|
||||
)
|
||||
]
|
||||
}.
|
||||
|
||||
autodetection_detailed_test_() ->
|
||||
{setup,
|
||||
fun setup/0,
|
||||
[
|
||||
?_assertMatch(
|
||||
[
|
||||
{yamerl_doc,
|
||||
{yamerl_seq,yamerl_node_seq,"tag:yaml.org,2002:seq",
|
||||
[{line,1},{column,1}],
|
||||
[
|
||||
{yamerl_erlang_atom,yamerl_node_erlang_atom,
|
||||
"tag:yamerl,2012:atom",
|
||||
[{line,1},{column,27}],
|
||||
atom},
|
||||
{yamerl_erlang_atom,yamerl_node_erlang_atom,
|
||||
"tag:yamerl,2012:atom",
|
||||
[{line,2},{column,27}],
|
||||
'atom requiring quoting!'},
|
||||
{yamerl_erlang_atom,yamerl_node_erlang_atom,
|
||||
"tag:yamerl,2012:atom",
|
||||
[{line,4},{column,3}],
|
||||
atom},
|
||||
{yamerl_erlang_atom,yamerl_node_erlang_atom,
|
||||
"tag:yamerl,2012:atom",
|
||||
[{line,5},{column,3}],
|
||||
node@domain},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,7},{column,3}],
|
||||
"not an atom"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,8},{column,3}],
|
||||
"NotAnAtom"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,9},{column,3}],
|
||||
"Not an atom"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,10},{column,3}],
|
||||
"Not an atom"}],
|
||||
8}}
|
||||
],
|
||||
yamerl_constr:file(?FILENAME, [
|
||||
{detailed_constr, true},
|
||||
{erlang_atom_autodetection, true}
|
||||
])
|
||||
)
|
||||
]
|
||||
}.
|
59
test/construction/erlang_atom_if_exist.erl
Normal file
59
test/construction/erlang_atom_if_exist.erl
Normal file
@ -0,0 +1,59 @@
|
||||
-module(erlang_atom_if_exist).
|
||||
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
|
||||
-define(FILENAME, "test/construction/" ?MODULE_STRING ".yaml").
|
||||
|
||||
setup() ->
|
||||
application:start(yamerl),
|
||||
yamerl_app:set_param(node_mods, [yamerl_node_erlang_atom]).
|
||||
|
||||
simple_test_() ->
|
||||
{setup,
|
||||
fun setup/0,
|
||||
[
|
||||
?_assertThrow(
|
||||
{yamerl_exception,
|
||||
[{yamerl_parsing_error, error,
|
||||
"Non-existing Erlang atom",
|
||||
1, 27,
|
||||
non_existing_erlang_atom,
|
||||
{yamerl_scalar, 1, 27,
|
||||
{yamerl_tag, 1, 3, "tag:yamerl,2012:atom"},
|
||||
flow, plain, "inexistent_atom"
|
||||
},
|
||||
[]
|
||||
}]
|
||||
},
|
||||
yamerl_constr:file(?FILENAME, [
|
||||
{detailed_constr, false},
|
||||
{erlang_atom_only_if_exist, true}
|
||||
])
|
||||
)
|
||||
]
|
||||
}.
|
||||
|
||||
detailed_test_() ->
|
||||
{setup,
|
||||
fun setup/0,
|
||||
[
|
||||
?_assertThrow(
|
||||
{yamerl_exception,
|
||||
[{yamerl_parsing_error, error,
|
||||
"Non-existing Erlang atom",
|
||||
1, 27,
|
||||
non_existing_erlang_atom,
|
||||
{yamerl_scalar, 1, 27,
|
||||
{yamerl_tag, 1, 3, "tag:yamerl,2012:atom"},
|
||||
flow, plain, "inexistent_atom"
|
||||
},
|
||||
[]
|
||||
}]
|
||||
},
|
||||
yamerl_constr:file(?FILENAME, [
|
||||
{detailed_constr, true},
|
||||
{erlang_atom_only_if_exist, true}
|
||||
])
|
||||
)
|
||||
]
|
||||
}.
|
47
test/construction/erlang_atom_if_exist_auto.erl
Normal file
47
test/construction/erlang_atom_if_exist_auto.erl
Normal file
@ -0,0 +1,47 @@
|
||||
-module(erlang_atom_if_exist_auto).
|
||||
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
|
||||
-define(FILENAME, "test/construction/" ?MODULE_STRING ".yaml").
|
||||
|
||||
setup() ->
|
||||
application:start(yamerl),
|
||||
yamerl_app:set_param(node_mods, [yamerl_node_erlang_atom]).
|
||||
|
||||
simple_test_() ->
|
||||
{setup,
|
||||
fun setup/0,
|
||||
[
|
||||
?_assertMatch(
|
||||
[
|
||||
"inexistent_atom"
|
||||
],
|
||||
yamerl_constr:file(?FILENAME, [
|
||||
{detailed_constr, false},
|
||||
{erlang_atom_autodetection, true},
|
||||
{erlang_atom_only_if_exist, true}
|
||||
])
|
||||
)
|
||||
]
|
||||
}.
|
||||
|
||||
detailed_test_() ->
|
||||
{setup,
|
||||
fun setup/0,
|
||||
[
|
||||
?_assertMatch(
|
||||
[
|
||||
{yamerl_doc,
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,1},{column,1}],
|
||||
"inexistent_atom"}
|
||||
}
|
||||
],
|
||||
yamerl_constr:file(?FILENAME, [
|
||||
{detailed_constr, true},
|
||||
{erlang_atom_autodetection, true},
|
||||
{erlang_atom_only_if_exist, true}
|
||||
])
|
||||
)
|
||||
]
|
||||
}.
|
47
test/construction/erlang_fun.erl
Normal file
47
test/construction/erlang_fun.erl
Normal file
@ -0,0 +1,47 @@
|
||||
-module(erlang_fun).
|
||||
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
|
||||
-define(FILENAME, "test/construction/" ?MODULE_STRING ".yaml").
|
||||
|
||||
setup() ->
|
||||
application:start(yamerl),
|
||||
yamerl_app:set_param(node_mods, [yamerl_node_erlang_fun]).
|
||||
|
||||
simple_test_() ->
|
||||
{setup,
|
||||
fun setup/0,
|
||||
[
|
||||
{generator,
|
||||
fun() ->
|
||||
[Erlang_Fun_Simple] = yamerl_constr:file(?FILENAME,
|
||||
[{detailed_constr, false}]),
|
||||
?_assertMatch(
|
||||
"Hello World!",
|
||||
Erlang_Fun_Simple()
|
||||
)
|
||||
end}
|
||||
]
|
||||
}.
|
||||
|
||||
detailed_test_() ->
|
||||
{setup,
|
||||
fun setup/0,
|
||||
[
|
||||
{generator,
|
||||
fun() ->
|
||||
[{yamerl_doc,
|
||||
{yamerl_erlang_fun,yamerl_node_erlang_fun,
|
||||
"tag:yamerl,2012:fun",
|
||||
[{line,1},{column,24}],
|
||||
Erlang_Fun_Normal,
|
||||
"fun() -> \"Hello World!\" end.\n"}}
|
||||
] = yamerl_constr:file(?FILENAME,
|
||||
[{detailed_constr, true}]),
|
||||
?_assertMatch(
|
||||
"Hello World!",
|
||||
Erlang_Fun_Normal()
|
||||
)
|
||||
end}
|
||||
]
|
||||
}.
|
695
test/construction/float.erl
Normal file
695
test/construction/float.erl
Normal file
@ -0,0 +1,695 @@
|
||||
-module(float).
|
||||
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
|
||||
-define(FILENAME, "test/construction/" ?MODULE_STRING ".yaml").
|
||||
|
||||
setup() ->
|
||||
application:start(yamerl).
|
||||
|
||||
schema_failsafe_simple_test_() ->
|
||||
{setup,
|
||||
fun setup/0,
|
||||
[
|
||||
?_assertMatch(
|
||||
[
|
||||
[
|
||||
"0", "+0", "-0",
|
||||
"123", "+123", "-123",
|
||||
"12.34", "+12.34", "-12.34",
|
||||
"12e10", "+12e10", "-12e10",
|
||||
"1.2e11", "1.2e+11", "1.2e-11",
|
||||
"1.0e10", "1.0E10",
|
||||
".", ".1", ".e+3", "1.", "1.e+3",
|
||||
"190:20:30.15", "+190:20:30.15", "-190:20:30.15",
|
||||
".inf", "+.inf", "-.inf", ".nan",
|
||||
".Inf", ".INF", ".iNF",
|
||||
".NaN", ".NAN", ".Nan", ".nAN",
|
||||
"Not a float.0e+10", "+Not a float.0e+10", "-Not a float.0e+10"
|
||||
]
|
||||
],
|
||||
yamerl_constr:file(?FILENAME,
|
||||
[{detailed_constr, false}, {schema, failsafe}]) %% No float parsing
|
||||
)
|
||||
]
|
||||
}.
|
||||
|
||||
schema_failsafe_float_json_simple_test_() ->
|
||||
{setup,
|
||||
fun setup/0,
|
||||
[
|
||||
?_assertMatch(
|
||||
[
|
||||
[
|
||||
0.0, "+0", 0.0,
|
||||
123.0, "+123", -123.0,
|
||||
12.34, "+12.34", -12.34,
|
||||
1.2e+11, "+12e10", -1.2e+11,
|
||||
1.2e+11, 1.2e+11, 1.2e-11,
|
||||
1.0e+10, 1.0e+10,
|
||||
".", ".1", ".e+3", 1.0, 1000.0,
|
||||
"190:20:30.15", "+190:20:30.15", "-190:20:30.15",
|
||||
'+inf', "+.inf", '-inf', 'nan',
|
||||
".Inf", ".INF", ".iNF",
|
||||
".NaN", ".NAN", ".Nan", ".nAN",
|
||||
"Not a float.0e+10", "+Not a float.0e+10", "-Not a float.0e+10"
|
||||
]
|
||||
],
|
||||
yamerl_constr:file(?FILENAME,
|
||||
[{detailed_constr, false}, {schema, failsafe},
|
||||
{node_mods, [yamerl_node_float_json]}])
|
||||
)
|
||||
]
|
||||
}.
|
||||
|
||||
schema_failsafe_float_simple_test_() ->
|
||||
{setup,
|
||||
fun setup/0,
|
||||
[
|
||||
?_assertMatch(
|
||||
[
|
||||
[
|
||||
0.0, 0.0, 0.0,
|
||||
123.0, 123.0, -123.0,
|
||||
12.34, 12.34, -12.34,
|
||||
1.2e+11, 1.2e+11, -1.2e+11,
|
||||
1.2e+11, 1.2e+11, 1.2e-11,
|
||||
1.0e+10, 1.0e+10,
|
||||
".", 0.1, ".e+3", 1.0, 1000.0,
|
||||
"190:20:30.15", "+190:20:30.15", "-190:20:30.15",
|
||||
'+inf', '+inf', '-inf', 'nan',
|
||||
'+inf', '+inf', ".iNF",
|
||||
'nan', 'nan', ".Nan", ".nAN",
|
||||
"Not a float.0e+10", "+Not a float.0e+10", "-Not a float.0e+10"
|
||||
]
|
||||
],
|
||||
yamerl_constr:file(?FILENAME,
|
||||
[{detailed_constr, false}, {schema, failsafe},
|
||||
{node_mods, [yamerl_node_float]}])
|
||||
)
|
||||
]
|
||||
}.
|
||||
|
||||
schema_failsafe_float_ext_simple_test_() ->
|
||||
{setup,
|
||||
fun setup/0,
|
||||
[
|
||||
?_assertMatch(
|
||||
[
|
||||
[
|
||||
0.0, 0.0, 0.0,
|
||||
"123", "+123", "-123",
|
||||
12.34, 12.34, -12.34,
|
||||
"12e10", "+12e10", "-12e10",
|
||||
"1.2e11", 1.2e+11, 1.2e-11,
|
||||
"1.0e10", "1.0E10",
|
||||
".", 0.1, 0.0, 1.0, 1000.0,
|
||||
685230.15, 685230.15, -685230.15,
|
||||
'+inf', '+inf', '-inf', 'nan',
|
||||
'+inf', '+inf', ".iNF",
|
||||
'nan', 'nan', ".Nan", ".nAN",
|
||||
"Not a float.0e+10", "+Not a float.0e+10", "-Not a float.0e+10"
|
||||
]
|
||||
],
|
||||
yamerl_constr:file(?FILENAME,
|
||||
[{detailed_constr, false}, {schema, failsafe},
|
||||
{node_mods, [yamerl_node_float_ext]}])
|
||||
)
|
||||
]
|
||||
}.
|
||||
|
||||
schema_failsafe_detailed_test_() ->
|
||||
{setup,
|
||||
fun setup/0,
|
||||
[
|
||||
?_assertMatch(
|
||||
[{yamerl_doc,
|
||||
{yamerl_seq,yamerl_node_seq,"tag:yaml.org,2002:seq",
|
||||
[{line,1},{column,1}],
|
||||
[
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,1},{column,4}],
|
||||
"0"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,2},{column,3}],
|
||||
"+0"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,3},{column,3}],
|
||||
"-0"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,5},{column,4}],
|
||||
"123"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,6},{column,3}],
|
||||
"+123"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,7},{column,3}],
|
||||
"-123"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,9},{column,4}],
|
||||
"12.34"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,10},{column,3}],
|
||||
"+12.34"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,11},{column,3}],
|
||||
"-12.34"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,13},{column,4}],
|
||||
"12e10"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,14},{column,3}],
|
||||
"+12e10"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,15},{column,3}],
|
||||
"-12e10"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,17},{column,3}],
|
||||
"1.2e11"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,18},{column,3}],
|
||||
"1.2e+11"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,19},{column,3}],
|
||||
"1.2e-11"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,21},{column,3}],
|
||||
"1.0e10"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,22},{column,3}],
|
||||
"1.0E10"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,24},{column,4}],
|
||||
"."},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,25},{column,4}],
|
||||
".1"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,26},{column,4}],
|
||||
".e+3"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,27},{column,3}],
|
||||
"1."},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,28},{column,3}],
|
||||
"1.e+3"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,30},{column,4}],
|
||||
"190:20:30.15"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,31},{column,3}],
|
||||
"+190:20:30.15"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,32},{column,3}],
|
||||
"-190:20:30.15"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,34},{column,4}],
|
||||
".inf"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,35},{column,3}],
|
||||
"+.inf"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,36},{column,3}],
|
||||
"-.inf"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,37},{column,4}],
|
||||
".nan"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,39},{column,3}],
|
||||
".Inf"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,40},{column,3}],
|
||||
".INF"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,41},{column,3}],
|
||||
".iNF"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,43},{column,3}],
|
||||
".NaN"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,44},{column,3}],
|
||||
".NAN"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,45},{column,3}],
|
||||
".Nan"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,46},{column,3}],
|
||||
".nAN"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,48},{column,4}],
|
||||
"Not a float.0e+10"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,49},{column,3}],
|
||||
"+Not a float.0e+10"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,50},{column,3}],
|
||||
"-Not a float.0e+10"}],
|
||||
39}}],
|
||||
yamerl_constr:file(?FILENAME,
|
||||
[{detailed_constr, true}, {schema, failsafe}]) %% No float parsing
|
||||
)
|
||||
]
|
||||
}.
|
||||
|
||||
schema_failsafe_float_json_detailed_test_() ->
|
||||
{setup,
|
||||
fun setup/0,
|
||||
[
|
||||
?_assertMatch(
|
||||
[{yamerl_doc,
|
||||
{yamerl_seq,yamerl_node_seq,"tag:yaml.org,2002:seq",
|
||||
[{line,1},{column,1}],
|
||||
[
|
||||
{yamerl_float,yamerl_node_float_json,
|
||||
"tag:yaml.org,2002:float",
|
||||
[{line,1},{column,4}],
|
||||
0.0},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,2},{column,3}],
|
||||
"+0"},
|
||||
{yamerl_float,yamerl_node_float_json,
|
||||
"tag:yaml.org,2002:float",
|
||||
[{line,3},{column,3}],
|
||||
0.0},
|
||||
{yamerl_float,yamerl_node_float_json,
|
||||
"tag:yaml.org,2002:float",
|
||||
[{line,5},{column,4}],
|
||||
123.0},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,6},{column,3}],
|
||||
"+123"},
|
||||
{yamerl_float,yamerl_node_float_json,
|
||||
"tag:yaml.org,2002:float",
|
||||
[{line,7},{column,3}],
|
||||
-123.0},
|
||||
{yamerl_float,yamerl_node_float_json,
|
||||
"tag:yaml.org,2002:float",
|
||||
[{line,9},{column,4}],
|
||||
12.34},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,10},{column,3}],
|
||||
"+12.34"},
|
||||
{yamerl_float,yamerl_node_float_json,
|
||||
"tag:yaml.org,2002:float",
|
||||
[{line,11},{column,3}],
|
||||
-12.34},
|
||||
{yamerl_float,yamerl_node_float_json,
|
||||
"tag:yaml.org,2002:float",
|
||||
[{line,13},{column,4}],
|
||||
1.2e11},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,14},{column,3}],
|
||||
"+12e10"},
|
||||
{yamerl_float,yamerl_node_float_json,
|
||||
"tag:yaml.org,2002:float",
|
||||
[{line,15},{column,3}],
|
||||
-1.2e11},
|
||||
{yamerl_float,yamerl_node_float_json,
|
||||
"tag:yaml.org,2002:float",
|
||||
[{line,17},{column,3}],
|
||||
1.2e11},
|
||||
{yamerl_float,yamerl_node_float_json,
|
||||
"tag:yaml.org,2002:float",
|
||||
[{line,18},{column,3}],
|
||||
1.2e11},
|
||||
{yamerl_float,yamerl_node_float_json,
|
||||
"tag:yaml.org,2002:float",
|
||||
[{line,19},{column,3}],
|
||||
1.2e-11},
|
||||
{yamerl_float,yamerl_node_float_json,
|
||||
"tag:yaml.org,2002:float",
|
||||
[{line,21},{column,3}],
|
||||
1.0e10},
|
||||
{yamerl_float,yamerl_node_float_json,
|
||||
"tag:yaml.org,2002:float",
|
||||
[{line,22},{column,3}],
|
||||
1.0e10},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,24},{column,4}],
|
||||
"."},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,25},{column,4}],
|
||||
".1"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,26},{column,4}],
|
||||
".e+3"},
|
||||
{yamerl_float,yamerl_node_float_json,
|
||||
"tag:yaml.org,2002:float",
|
||||
[{line,27},{column,3}],
|
||||
1.0},
|
||||
{yamerl_float,yamerl_node_float_json,
|
||||
"tag:yaml.org,2002:float",
|
||||
[{line,28},{column,3}],
|
||||
1000.0},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,30},{column,4}],
|
||||
"190:20:30.15"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,31},{column,3}],
|
||||
"+190:20:30.15"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,32},{column,3}],
|
||||
"-190:20:30.15"},
|
||||
{yamerl_float,yamerl_node_float_json,
|
||||
"tag:yaml.org,2002:float",
|
||||
[{line,34},{column,4}],
|
||||
'+inf'},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,35},{column,3}],
|
||||
"+.inf"},
|
||||
{yamerl_float,yamerl_node_float_json,
|
||||
"tag:yaml.org,2002:float",
|
||||
[{line,36},{column,3}],
|
||||
'-inf'},
|
||||
{yamerl_float,yamerl_node_float_json,
|
||||
"tag:yaml.org,2002:float",
|
||||
[{line,37},{column,4}],
|
||||
nan},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,39},{column,3}],
|
||||
".Inf"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,40},{column,3}],
|
||||
".INF"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,41},{column,3}],
|
||||
".iNF"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,43},{column,3}],
|
||||
".NaN"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,44},{column,3}],
|
||||
".NAN"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,45},{column,3}],
|
||||
".Nan"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,46},{column,3}],
|
||||
".nAN"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,48},{column,4}],
|
||||
"Not a float.0e+10"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,49},{column,3}],
|
||||
"+Not a float.0e+10"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,50},{column,3}],
|
||||
"-Not a float.0e+10"}],
|
||||
39}}],
|
||||
yamerl_constr:file(?FILENAME,
|
||||
[{detailed_constr, true}, {schema, failsafe},
|
||||
{node_mods, [yamerl_node_float_json]}])
|
||||
)
|
||||
]
|
||||
}.
|
||||
|
||||
schema_failsafe_float_detailed_test_() ->
|
||||
{setup,
|
||||
fun setup/0,
|
||||
[
|
||||
?_assertMatch(
|
||||
[{yamerl_doc,
|
||||
{yamerl_seq,yamerl_node_seq,"tag:yaml.org,2002:seq",
|
||||
[{line,1},{column,1}],
|
||||
[
|
||||
{yamerl_float,yamerl_node_float,"tag:yaml.org,2002:float",
|
||||
[{line,1},{column,4}],
|
||||
0.0},
|
||||
{yamerl_float,yamerl_node_float,"tag:yaml.org,2002:float",
|
||||
[{line,2},{column,3}],
|
||||
0.0},
|
||||
{yamerl_float,yamerl_node_float,"tag:yaml.org,2002:float",
|
||||
[{line,3},{column,3}],
|
||||
0.0},
|
||||
{yamerl_float,yamerl_node_float,"tag:yaml.org,2002:float",
|
||||
[{line,5},{column,4}],
|
||||
123.0},
|
||||
{yamerl_float,yamerl_node_float,"tag:yaml.org,2002:float",
|
||||
[{line,6},{column,3}],
|
||||
123.0},
|
||||
{yamerl_float,yamerl_node_float,"tag:yaml.org,2002:float",
|
||||
[{line,7},{column,3}],
|
||||
-123.0},
|
||||
{yamerl_float,yamerl_node_float,"tag:yaml.org,2002:float",
|
||||
[{line,9},{column,4}],
|
||||
12.34},
|
||||
{yamerl_float,yamerl_node_float,"tag:yaml.org,2002:float",
|
||||
[{line,10},{column,3}],
|
||||
12.34},
|
||||
{yamerl_float,yamerl_node_float,"tag:yaml.org,2002:float",
|
||||
[{line,11},{column,3}],
|
||||
-12.34},
|
||||
{yamerl_float,yamerl_node_float,"tag:yaml.org,2002:float",
|
||||
[{line,13},{column,4}],
|
||||
1.2e11},
|
||||
{yamerl_float,yamerl_node_float,"tag:yaml.org,2002:float",
|
||||
[{line,14},{column,3}],
|
||||
1.2e11},
|
||||
{yamerl_float,yamerl_node_float,"tag:yaml.org,2002:float",
|
||||
[{line,15},{column,3}],
|
||||
-1.2e11},
|
||||
{yamerl_float,yamerl_node_float,"tag:yaml.org,2002:float",
|
||||
[{line,17},{column,3}],
|
||||
1.2e11},
|
||||
{yamerl_float,yamerl_node_float,"tag:yaml.org,2002:float",
|
||||
[{line,18},{column,3}],
|
||||
1.2e11},
|
||||
{yamerl_float,yamerl_node_float,"tag:yaml.org,2002:float",
|
||||
[{line,19},{column,3}],
|
||||
1.2e-11},
|
||||
{yamerl_float,yamerl_node_float,"tag:yaml.org,2002:float",
|
||||
[{line,21},{column,3}],
|
||||
1.0e10},
|
||||
{yamerl_float,yamerl_node_float,"tag:yaml.org,2002:float",
|
||||
[{line,22},{column,3}],
|
||||
1.0e10},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,24},{column,4}],
|
||||
"."},
|
||||
{yamerl_float,yamerl_node_float,"tag:yaml.org,2002:float",
|
||||
[{line,25},{column,4}],
|
||||
0.1},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,26},{column,4}],
|
||||
".e+3"},
|
||||
{yamerl_float,yamerl_node_float,"tag:yaml.org,2002:float",
|
||||
[{line,27},{column,3}],
|
||||
1.0},
|
||||
{yamerl_float,yamerl_node_float,"tag:yaml.org,2002:float",
|
||||
[{line,28},{column,3}],
|
||||
1000.0},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,30},{column,4}],
|
||||
"190:20:30.15"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,31},{column,3}],
|
||||
"+190:20:30.15"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,32},{column,3}],
|
||||
"-190:20:30.15"},
|
||||
{yamerl_float,yamerl_node_float,"tag:yaml.org,2002:float",
|
||||
[{line,34},{column,4}],
|
||||
'+inf'},
|
||||
{yamerl_float,yamerl_node_float,"tag:yaml.org,2002:float",
|
||||
[{line,35},{column,3}],
|
||||
'+inf'},
|
||||
{yamerl_float,yamerl_node_float,"tag:yaml.org,2002:float",
|
||||
[{line,36},{column,3}],
|
||||
'-inf'},
|
||||
{yamerl_float,yamerl_node_float,"tag:yaml.org,2002:float",
|
||||
[{line,37},{column,4}],
|
||||
nan},
|
||||
{yamerl_float,yamerl_node_float,"tag:yaml.org,2002:float",
|
||||
[{line,39},{column,3}],
|
||||
'+inf'},
|
||||
{yamerl_float,yamerl_node_float,"tag:yaml.org,2002:float",
|
||||
[{line,40},{column,3}],
|
||||
'+inf'},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,41},{column,3}],
|
||||
".iNF"},
|
||||
{yamerl_float,yamerl_node_float,"tag:yaml.org,2002:float",
|
||||
[{line,43},{column,3}],
|
||||
nan},
|
||||
{yamerl_float,yamerl_node_float,"tag:yaml.org,2002:float",
|
||||
[{line,44},{column,3}],
|
||||
nan},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,45},{column,3}],
|
||||
".Nan"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,46},{column,3}],
|
||||
".nAN"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,48},{column,4}],
|
||||
"Not a float.0e+10"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,49},{column,3}],
|
||||
"+Not a float.0e+10"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,50},{column,3}],
|
||||
"-Not a float.0e+10"}],
|
||||
39}}],
|
||||
yamerl_constr:file(?FILENAME,
|
||||
[{detailed_constr, true}, {schema, failsafe},
|
||||
{node_mods, [yamerl_node_float]}])
|
||||
)
|
||||
]
|
||||
}.
|
||||
|
||||
schema_failsafe_float_ext_detailed_test_() ->
|
||||
{setup,
|
||||
fun setup/0,
|
||||
[
|
||||
?_assertMatch(
|
||||
[{yamerl_doc,
|
||||
{yamerl_seq,yamerl_node_seq,"tag:yaml.org,2002:seq",
|
||||
[{line,1},{column,1}],
|
||||
[
|
||||
{yamerl_float,yamerl_node_float_ext,
|
||||
"tag:yaml.org,2002:float",
|
||||
[{line,1},{column,4}],
|
||||
0.0},
|
||||
{yamerl_float,yamerl_node_float_ext,
|
||||
"tag:yaml.org,2002:float",
|
||||
[{line,2},{column,3}],
|
||||
0.0},
|
||||
{yamerl_float,yamerl_node_float_ext,
|
||||
"tag:yaml.org,2002:float",
|
||||
[{line,3},{column,3}],
|
||||
0.0},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,5},{column,4}],
|
||||
"123"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,6},{column,3}],
|
||||
"+123"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,7},{column,3}],
|
||||
"-123"},
|
||||
{yamerl_float,yamerl_node_float_ext,
|
||||
"tag:yaml.org,2002:float",
|
||||
[{line,9},{column,4}],
|
||||
12.34},
|
||||
{yamerl_float,yamerl_node_float_ext,
|
||||
"tag:yaml.org,2002:float",
|
||||
[{line,10},{column,3}],
|
||||
12.34},
|
||||
{yamerl_float,yamerl_node_float_ext,
|
||||
"tag:yaml.org,2002:float",
|
||||
[{line,11},{column,3}],
|
||||
-12.34},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,13},{column,4}],
|
||||
"12e10"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,14},{column,3}],
|
||||
"+12e10"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,15},{column,3}],
|
||||
"-12e10"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,17},{column,3}],
|
||||
"1.2e11"},
|
||||
{yamerl_float,yamerl_node_float_ext,
|
||||
"tag:yaml.org,2002:float",
|
||||
[{line,18},{column,3}],
|
||||
1.2e11},
|
||||
{yamerl_float,yamerl_node_float_ext,
|
||||
"tag:yaml.org,2002:float",
|
||||
[{line,19},{column,3}],
|
||||
1.2e-11},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,21},{column,3}],
|
||||
"1.0e10"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,22},{column,3}],
|
||||
"1.0E10"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,24},{column,4}],
|
||||
"."},
|
||||
{yamerl_float,yamerl_node_float_ext,
|
||||
"tag:yaml.org,2002:float",
|
||||
[{line,25},{column,4}],
|
||||
0.1},
|
||||
{yamerl_float,yamerl_node_float_ext,
|
||||
"tag:yaml.org,2002:float",
|
||||
[{line,26},{column,4}],
|
||||
0.0},
|
||||
{yamerl_float,yamerl_node_float_ext,
|
||||
"tag:yaml.org,2002:float",
|
||||
[{line,27},{column,3}],
|
||||
1.0},
|
||||
{yamerl_float,yamerl_node_float_ext,
|
||||
"tag:yaml.org,2002:float",
|
||||
[{line,28},{column,3}],
|
||||
1000.0},
|
||||
{yamerl_float,yamerl_node_float_ext,
|
||||
"tag:yaml.org,2002:float",
|
||||
[{line,30},{column,4}],
|
||||
685230.15},
|
||||
{yamerl_float,yamerl_node_float_ext,
|
||||
"tag:yaml.org,2002:float",
|
||||
[{line,31},{column,3}],
|
||||
685230.15},
|
||||
{yamerl_float,yamerl_node_float_ext,
|
||||
"tag:yaml.org,2002:float",
|
||||
[{line,32},{column,3}],
|
||||
-685230.15},
|
||||
{yamerl_float,yamerl_node_float_ext,
|
||||
"tag:yaml.org,2002:float",
|
||||
[{line,34},{column,4}],
|
||||
'+inf'},
|
||||
{yamerl_float,yamerl_node_float_ext,
|
||||
"tag:yaml.org,2002:float",
|
||||
[{line,35},{column,3}],
|
||||
'+inf'},
|
||||
{yamerl_float,yamerl_node_float_ext,
|
||||
"tag:yaml.org,2002:float",
|
||||
[{line,36},{column,3}],
|
||||
'-inf'},
|
||||
{yamerl_float,yamerl_node_float_ext,
|
||||
"tag:yaml.org,2002:float",
|
||||
[{line,37},{column,4}],
|
||||
nan},
|
||||
{yamerl_float,yamerl_node_float_ext,
|
||||
"tag:yaml.org,2002:float",
|
||||
[{line,39},{column,3}],
|
||||
'+inf'},
|
||||
{yamerl_float,yamerl_node_float_ext,
|
||||
"tag:yaml.org,2002:float",
|
||||
[{line,40},{column,3}],
|
||||
'+inf'},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,41},{column,3}],
|
||||
".iNF"},
|
||||
{yamerl_float,yamerl_node_float_ext,
|
||||
"tag:yaml.org,2002:float",
|
||||
[{line,43},{column,3}],
|
||||
nan},
|
||||
{yamerl_float,yamerl_node_float_ext,
|
||||
"tag:yaml.org,2002:float",
|
||||
[{line,44},{column,3}],
|
||||
nan},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,45},{column,3}],
|
||||
".Nan"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,46},{column,3}],
|
||||
".nAN"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,48},{column,4}],
|
||||
"Not a float.0e+10"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,49},{column,3}],
|
||||
"+Not a float.0e+10"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,50},{column,3}],
|
||||
"-Not a float.0e+10"}],
|
||||
39}}],
|
||||
yamerl_constr:file(?FILENAME,
|
||||
[{detailed_constr, true}, {schema, failsafe},
|
||||
{node_mods, [yamerl_node_float_ext]}])
|
||||
)
|
||||
]
|
||||
}.
|
546
test/construction/int.erl
Normal file
546
test/construction/int.erl
Normal file
@ -0,0 +1,546 @@
|
||||
-module(int).
|
||||
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
|
||||
-define(FILENAME, "test/construction/" ?MODULE_STRING ".yaml").
|
||||
|
||||
setup() ->
|
||||
application:start(yamerl).
|
||||
|
||||
schema_failsafe_simple_test_() ->
|
||||
{setup,
|
||||
fun setup/0,
|
||||
[
|
||||
?_assertMatch(
|
||||
[
|
||||
[
|
||||
"0", "+0", "-0",
|
||||
"123", "+123", "-123",
|
||||
"0b101", "+0b101", "-0b101",
|
||||
"0o123", "+0o123", "-0o123",
|
||||
"0123", "+0123", "-0123",
|
||||
"0x1aB", "+0x1aB", "-0x1aB",
|
||||
"123:1:23", "+123:1:23", "-123:1:23",
|
||||
"1_234", "0b10_10", "0o12_34", "012_34", "0xc3_A9", "1_234:56:8",
|
||||
"Not an int", "+Not an int", "-Not an int"
|
||||
]
|
||||
],
|
||||
yamerl_constr:file(?FILENAME,
|
||||
[{detailed_constr, false}, {schema, failsafe}]) %% No integer parsing
|
||||
)
|
||||
]
|
||||
}.
|
||||
|
||||
schema_failsafe_int_json_simple_test_() ->
|
||||
{setup,
|
||||
fun setup/0,
|
||||
[
|
||||
?_assertMatch(
|
||||
[
|
||||
[
|
||||
0, "+0", 0,
|
||||
123, "+123", -123,
|
||||
"0b101", "+0b101", "-0b101",
|
||||
"0o123", "+0o123", "-0o123",
|
||||
"0123", "+0123", "-0123",
|
||||
"0x1aB", "+0x1aB", "-0x1aB",
|
||||
"123:1:23", "+123:1:23", "-123:1:23",
|
||||
"1_234", "0b10_10", "0o12_34", "012_34", "0xc3_A9", "1_234:56:8",
|
||||
"Not an int", "+Not an int", "-Not an int"
|
||||
]
|
||||
],
|
||||
yamerl_constr:file(?FILENAME,
|
||||
[{detailed_constr, false}, {schema, failsafe},
|
||||
{node_mods, [yamerl_node_int_json]}])
|
||||
)
|
||||
]
|
||||
}.
|
||||
|
||||
schema_failsafe_int_simple_test_() ->
|
||||
{setup,
|
||||
fun setup/0,
|
||||
[
|
||||
?_assertMatch(
|
||||
[
|
||||
[
|
||||
0, 0, 0,
|
||||
123, 123, -123,
|
||||
"0b101", "+0b101", "-0b101",
|
||||
83, 83, -83,
|
||||
123, 123, -123,
|
||||
427, 427, -427,
|
||||
"123:1:23", "+123:1:23", "-123:1:23",
|
||||
"1_234", "0b10_10", "0o12_34", "012_34", "0xc3_A9", "1_234:56:8",
|
||||
"Not an int", "+Not an int", "-Not an int"
|
||||
]
|
||||
],
|
||||
yamerl_constr:file(?FILENAME,
|
||||
[{detailed_constr, false}, {schema, failsafe},
|
||||
{node_mods, [yamerl_node_int]}])
|
||||
)
|
||||
]
|
||||
}.
|
||||
|
||||
schema_failsafe_int_ext_simple_test_() ->
|
||||
{setup,
|
||||
fun setup/0,
|
||||
[
|
||||
?_assertMatch(
|
||||
[
|
||||
[
|
||||
0, 0, 0,
|
||||
123, 123, -123,
|
||||
5, 5, -5,
|
||||
"0o123", "+0o123", "-0o123",
|
||||
83, 83, -83,
|
||||
427, 427, -427,
|
||||
442883, 442883, -442883,
|
||||
1234, 10, "0o12_34", 668, 50089, 4445768,
|
||||
"Not an int", "+Not an int", "-Not an int"
|
||||
]
|
||||
],
|
||||
yamerl_constr:file(?FILENAME,
|
||||
[{detailed_constr, false}, {schema, failsafe},
|
||||
{node_mods, [yamerl_node_int_ext]}])
|
||||
)
|
||||
]
|
||||
}.
|
||||
|
||||
schema_failsafe_detailed_test_() ->
|
||||
{setup,
|
||||
fun setup/0,
|
||||
[
|
||||
?_assertMatch(
|
||||
[
|
||||
{yamerl_doc,
|
||||
{yamerl_seq,yamerl_node_seq,"tag:yaml.org,2002:seq",
|
||||
[{line,1},{column,1}],
|
||||
[{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,1},{column,4}],
|
||||
"0"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,2},{column,3}],
|
||||
"+0"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,3},{column,3}],
|
||||
"-0"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,5},{column,4}],
|
||||
"123"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,6},{column,3}],
|
||||
"+123"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,7},{column,3}],
|
||||
"-123"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,9},{column,4}],
|
||||
"0b101"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,10},{column,3}],
|
||||
"+0b101"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,11},{column,3}],
|
||||
"-0b101"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,13},{column,4}],
|
||||
"0o123"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,14},{column,3}],
|
||||
"+0o123"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,15},{column,3}],
|
||||
"-0o123"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,17},{column,4}],
|
||||
"0123"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,18},{column,3}],
|
||||
"+0123"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,19},{column,3}],
|
||||
"-0123"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,21},{column,4}],
|
||||
"0x1aB"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,22},{column,3}],
|
||||
"+0x1aB"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,23},{column,3}],
|
||||
"-0x1aB"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,25},{column,4}],
|
||||
"123:1:23"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,26},{column,3}],
|
||||
"+123:1:23"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,27},{column,3}],
|
||||
"-123:1:23"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,29},{column,3}],
|
||||
"1_234"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,30},{column,3}],
|
||||
"0b10_10"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,31},{column,3}],
|
||||
"0o12_34"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,32},{column,3}],
|
||||
"012_34"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,33},{column,3}],
|
||||
"0xc3_A9"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,34},{column,3}],
|
||||
"1_234:56:8"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,36},{column,4}],
|
||||
"Not an int"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,37},{column,3}],
|
||||
"+Not an int"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,38},{column,3}],
|
||||
"-Not an int"}],
|
||||
30}
|
||||
}
|
||||
],
|
||||
yamerl_constr:file(?FILENAME,
|
||||
[{detailed_constr, true}, {schema, failsafe}]) %% No integer parsing
|
||||
)
|
||||
]
|
||||
}.
|
||||
|
||||
schema_failsafe_int_json_detailed_test_() ->
|
||||
{setup,
|
||||
fun setup/0,
|
||||
[
|
||||
?_assertMatch(
|
||||
[
|
||||
{yamerl_doc,
|
||||
{yamerl_seq,yamerl_node_seq,"tag:yaml.org,2002:seq",
|
||||
[{line,1},{column,1}],
|
||||
[{yamerl_int,yamerl_node_int_json,
|
||||
"tag:yaml.org,2002:int",
|
||||
[{line,1},{column,4}],
|
||||
0},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,2},{column,3}],
|
||||
"+0"},
|
||||
{yamerl_int,yamerl_node_int_json,
|
||||
"tag:yaml.org,2002:int",
|
||||
[{line,3},{column,3}],
|
||||
0},
|
||||
{yamerl_int,yamerl_node_int_json,
|
||||
"tag:yaml.org,2002:int",
|
||||
[{line,5},{column,4}],
|
||||
123},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,6},{column,3}],
|
||||
"+123"},
|
||||
{yamerl_int,yamerl_node_int_json,
|
||||
"tag:yaml.org,2002:int",
|
||||
[{line,7},{column,3}],
|
||||
-123},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,9},{column,4}],
|
||||
"0b101"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,10},{column,3}],
|
||||
"+0b101"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,11},{column,3}],
|
||||
"-0b101"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,13},{column,4}],
|
||||
"0o123"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,14},{column,3}],
|
||||
"+0o123"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,15},{column,3}],
|
||||
"-0o123"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,17},{column,4}],
|
||||
"0123"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,18},{column,3}],
|
||||
"+0123"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,19},{column,3}],
|
||||
"-0123"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,21},{column,4}],
|
||||
"0x1aB"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,22},{column,3}],
|
||||
"+0x1aB"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,23},{column,3}],
|
||||
"-0x1aB"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,25},{column,4}],
|
||||
"123:1:23"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,26},{column,3}],
|
||||
"+123:1:23"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,27},{column,3}],
|
||||
"-123:1:23"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,29},{column,3}],
|
||||
"1_234"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,30},{column,3}],
|
||||
"0b10_10"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,31},{column,3}],
|
||||
"0o12_34"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,32},{column,3}],
|
||||
"012_34"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,33},{column,3}],
|
||||
"0xc3_A9"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,34},{column,3}],
|
||||
"1_234:56:8"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,36},{column,4}],
|
||||
"Not an int"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,37},{column,3}],
|
||||
"+Not an int"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,38},{column,3}],
|
||||
"-Not an int"}],
|
||||
30}
|
||||
}
|
||||
],
|
||||
yamerl_constr:file(?FILENAME,
|
||||
[{detailed_constr, true}, {schema, failsafe},
|
||||
{node_mods, [yamerl_node_int_json]}])
|
||||
)
|
||||
]
|
||||
}.
|
||||
|
||||
schema_failsafe_int_detailed_test_() ->
|
||||
{setup,
|
||||
fun setup/0,
|
||||
[
|
||||
?_assertMatch(
|
||||
[
|
||||
{yamerl_doc,
|
||||
{yamerl_seq,yamerl_node_seq,"tag:yaml.org,2002:seq",
|
||||
[{line,1},{column,1}],
|
||||
[{yamerl_int,yamerl_node_int,"tag:yaml.org,2002:int",
|
||||
[{line,1},{column,4}],
|
||||
0},
|
||||
{yamerl_int,yamerl_node_int,"tag:yaml.org,2002:int",
|
||||
[{line,2},{column,3}],
|
||||
0},
|
||||
{yamerl_int,yamerl_node_int,"tag:yaml.org,2002:int",
|
||||
[{line,3},{column,3}],
|
||||
0},
|
||||
{yamerl_int,yamerl_node_int,"tag:yaml.org,2002:int",
|
||||
[{line,5},{column,4}],
|
||||
123},
|
||||
{yamerl_int,yamerl_node_int,"tag:yaml.org,2002:int",
|
||||
[{line,6},{column,3}],
|
||||
123},
|
||||
{yamerl_int,yamerl_node_int,"tag:yaml.org,2002:int",
|
||||
[{line,7},{column,3}],
|
||||
-123},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,9},{column,4}],
|
||||
"0b101"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,10},{column,3}],
|
||||
"+0b101"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,11},{column,3}],
|
||||
"-0b101"},
|
||||
{yamerl_int,yamerl_node_int,"tag:yaml.org,2002:int",
|
||||
[{line,13},{column,4}],
|
||||
83},
|
||||
{yamerl_int,yamerl_node_int,"tag:yaml.org,2002:int",
|
||||
[{line,14},{column,3}],
|
||||
83},
|
||||
{yamerl_int,yamerl_node_int,"tag:yaml.org,2002:int",
|
||||
[{line,15},{column,3}],
|
||||
-83},
|
||||
{yamerl_int,yamerl_node_int,"tag:yaml.org,2002:int",
|
||||
[{line,17},{column,4}],
|
||||
123},
|
||||
{yamerl_int,yamerl_node_int,"tag:yaml.org,2002:int",
|
||||
[{line,18},{column,3}],
|
||||
123},
|
||||
{yamerl_int,yamerl_node_int,"tag:yaml.org,2002:int",
|
||||
[{line,19},{column,3}],
|
||||
-123},
|
||||
{yamerl_int,yamerl_node_int,"tag:yaml.org,2002:int",
|
||||
[{line,21},{column,4}],
|
||||
427},
|
||||
{yamerl_int,yamerl_node_int,"tag:yaml.org,2002:int",
|
||||
[{line,22},{column,3}],
|
||||
427},
|
||||
{yamerl_int,yamerl_node_int,"tag:yaml.org,2002:int",
|
||||
[{line,23},{column,3}],
|
||||
-427},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,25},{column,4}],
|
||||
"123:1:23"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,26},{column,3}],
|
||||
"+123:1:23"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,27},{column,3}],
|
||||
"-123:1:23"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,29},{column,3}],
|
||||
"1_234"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,30},{column,3}],
|
||||
"0b10_10"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,31},{column,3}],
|
||||
"0o12_34"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,32},{column,3}],
|
||||
"012_34"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,33},{column,3}],
|
||||
"0xc3_A9"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,34},{column,3}],
|
||||
"1_234:56:8"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,36},{column,4}],
|
||||
"Not an int"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,37},{column,3}],
|
||||
"+Not an int"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,38},{column,3}],
|
||||
"-Not an int"}],
|
||||
30}
|
||||
}
|
||||
],
|
||||
yamerl_constr:file(?FILENAME,
|
||||
[{detailed_constr, true}, {schema, failsafe},
|
||||
{node_mods, [yamerl_node_int]}])
|
||||
)
|
||||
]
|
||||
}.
|
||||
|
||||
schema_failsafe_int_ext_detailed_test_() ->
|
||||
{setup,
|
||||
fun setup/0,
|
||||
[
|
||||
?_assertMatch(
|
||||
[
|
||||
{yamerl_doc,
|
||||
{yamerl_seq,yamerl_node_seq,"tag:yaml.org,2002:seq",
|
||||
[{line,1},{column,1}],
|
||||
[{yamerl_int,yamerl_node_int_ext,"tag:yaml.org,2002:int",
|
||||
[{line,1},{column,4}],
|
||||
0},
|
||||
{yamerl_int,yamerl_node_int_ext,"tag:yaml.org,2002:int",
|
||||
[{line,2},{column,3}],
|
||||
0},
|
||||
{yamerl_int,yamerl_node_int_ext,"tag:yaml.org,2002:int",
|
||||
[{line,3},{column,3}],
|
||||
0},
|
||||
{yamerl_int,yamerl_node_int_ext,"tag:yaml.org,2002:int",
|
||||
[{line,5},{column,4}],
|
||||
123},
|
||||
{yamerl_int,yamerl_node_int_ext,"tag:yaml.org,2002:int",
|
||||
[{line,6},{column,3}],
|
||||
123},
|
||||
{yamerl_int,yamerl_node_int_ext,"tag:yaml.org,2002:int",
|
||||
[{line,7},{column,3}],
|
||||
-123},
|
||||
{yamerl_int,yamerl_node_int_ext,"tag:yaml.org,2002:int",
|
||||
[{line,9},{column,4}],
|
||||
5},
|
||||
{yamerl_int,yamerl_node_int_ext,"tag:yaml.org,2002:int",
|
||||
[{line,10},{column,3}],
|
||||
5},
|
||||
{yamerl_int,yamerl_node_int_ext,"tag:yaml.org,2002:int",
|
||||
[{line,11},{column,3}],
|
||||
-5},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,13},{column,4}],
|
||||
"0o123"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,14},{column,3}],
|
||||
"+0o123"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,15},{column,3}],
|
||||
"-0o123"},
|
||||
{yamerl_int,yamerl_node_int_ext,"tag:yaml.org,2002:int",
|
||||
[{line,17},{column,4}],
|
||||
83},
|
||||
{yamerl_int,yamerl_node_int_ext,"tag:yaml.org,2002:int",
|
||||
[{line,18},{column,3}],
|
||||
83},
|
||||
{yamerl_int,yamerl_node_int_ext,"tag:yaml.org,2002:int",
|
||||
[{line,19},{column,3}],
|
||||
-83},
|
||||
{yamerl_int,yamerl_node_int_ext,"tag:yaml.org,2002:int",
|
||||
[{line,21},{column,4}],
|
||||
427},
|
||||
{yamerl_int,yamerl_node_int_ext,"tag:yaml.org,2002:int",
|
||||
[{line,22},{column,3}],
|
||||
427},
|
||||
{yamerl_int,yamerl_node_int_ext,"tag:yaml.org,2002:int",
|
||||
[{line,23},{column,3}],
|
||||
-427},
|
||||
{yamerl_int,yamerl_node_int_ext,"tag:yaml.org,2002:int",
|
||||
[{line,25},{column,4}],
|
||||
442883},
|
||||
{yamerl_int,yamerl_node_int_ext,"tag:yaml.org,2002:int",
|
||||
[{line,26},{column,3}],
|
||||
442883},
|
||||
{yamerl_int,yamerl_node_int_ext,"tag:yaml.org,2002:int",
|
||||
[{line,27},{column,3}],
|
||||
-442883},
|
||||
{yamerl_int,yamerl_node_int_ext,"tag:yaml.org,2002:int",
|
||||
[{line,29},{column,3}],
|
||||
1234},
|
||||
{yamerl_int,yamerl_node_int_ext,"tag:yaml.org,2002:int",
|
||||
[{line,30},{column,3}],
|
||||
10},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,31},{column,3}],
|
||||
"0o12_34"},
|
||||
{yamerl_int,yamerl_node_int_ext,"tag:yaml.org,2002:int",
|
||||
[{line,32},{column,3}],
|
||||
668},
|
||||
{yamerl_int,yamerl_node_int_ext,"tag:yaml.org,2002:int",
|
||||
[{line,33},{column,3}],
|
||||
50089},
|
||||
{yamerl_int,yamerl_node_int_ext,"tag:yaml.org,2002:int",
|
||||
[{line,34},{column,3}],
|
||||
4445768},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,36},{column,4}],
|
||||
"Not an int"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,37},{column,3}],
|
||||
"+Not an int"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,38},{column,3}],
|
||||
"-Not an int"}],
|
||||
30}
|
||||
}
|
||||
],
|
||||
yamerl_constr:file(?FILENAME,
|
||||
[{detailed_constr, true}, {schema, failsafe},
|
||||
{node_mods, [yamerl_node_int_ext]}])
|
||||
)
|
||||
]
|
||||
}.
|
77
test/construction/ipaddr.erl
Normal file
77
test/construction/ipaddr.erl
Normal file
@ -0,0 +1,77 @@
|
||||
-module(ipaddr).
|
||||
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
|
||||
-define(FILENAME, "test/construction/" ?MODULE_STRING ".yaml").
|
||||
|
||||
setup() ->
|
||||
application:start(yamerl),
|
||||
yamerl_app:set_param(node_mods, [yamerl_node_ipaddr]).
|
||||
|
||||
simple_test_() ->
|
||||
{setup,
|
||||
fun setup/0,
|
||||
[
|
||||
?_assertMatch(
|
||||
[
|
||||
[
|
||||
{192, 168, 1, 10},
|
||||
{{192, 168, 1, 10}, 24},
|
||||
{{192, 168, 1, 10}, {192, 168, 1, 20}},
|
||||
{8193,16848,1,28696,0,0,1,2},
|
||||
{{8193,16848,1,28696,0,0,1,0},64},
|
||||
{{8193,16848,1,28696,0,0,1,2},{8193,16848,1,28696,0,0,1,5}},
|
||||
"Not an IP address"
|
||||
]
|
||||
],
|
||||
yamerl_constr:file(?FILENAME, [{detailed_constr, false}])
|
||||
)
|
||||
]
|
||||
}.
|
||||
|
||||
detailed_test_() ->
|
||||
{setup,
|
||||
fun setup/0,
|
||||
[
|
||||
?_assertMatch(
|
||||
[
|
||||
{yamerl_doc,
|
||||
{yamerl_seq,yamerl_node_seq,"tag:yaml.org,2002:seq",
|
||||
[{line,1},{column,1}],
|
||||
[{yamerl_ip_addr,yamerl_node_ipaddr,
|
||||
"tag:yamerl,2012:ipaddr",
|
||||
[{line,1},{column,3}],
|
||||
{192,168,1,10}},
|
||||
{yamerl_ip_netmask,yamerl_node_ipaddr,
|
||||
"tag:yamerl,2012:ipaddr",
|
||||
[{line,2},{column,3}],
|
||||
{192,168,1,10},
|
||||
24},
|
||||
{yamerl_ip_range,yamerl_node_ipaddr,
|
||||
"tag:yamerl,2012:ipaddr",
|
||||
[{line,3},{column,3}],
|
||||
{192,168,1,10},
|
||||
{192,168,1,20}},
|
||||
{yamerl_ip_addr,yamerl_node_ipaddr,
|
||||
"tag:yamerl,2012:ipaddr",
|
||||
[{line,5},{column,3}],
|
||||
{8193,16848,1,28696,0,0,1,2}},
|
||||
{yamerl_ip_netmask,yamerl_node_ipaddr,
|
||||
"tag:yamerl,2012:ipaddr",
|
||||
[{line,6},{column,3}],
|
||||
{8193,16848,1,28696,0,0,1,0},
|
||||
64},
|
||||
{yamerl_ip_range,yamerl_node_ipaddr,
|
||||
"tag:yamerl,2012:ipaddr",
|
||||
[{line,7},{column,3}],
|
||||
{8193,16848,1,28696,0,0,1,2},
|
||||
{8193,16848,1,28696,0,0,1,5}},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,9},{column,3}],
|
||||
"Not an IP address"}],
|
||||
7}}
|
||||
],
|
||||
yamerl_constr:file(?FILENAME, [{detailed_constr, true}])
|
||||
)
|
||||
]
|
||||
}.
|
65
test/construction/map.erl
Normal file
65
test/construction/map.erl
Normal file
@ -0,0 +1,65 @@
|
||||
-module(map).
|
||||
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
|
||||
-define(FILENAME, "test/construction/" ?MODULE_STRING ".yaml").
|
||||
|
||||
setup() ->
|
||||
application:start(yamerl).
|
||||
|
||||
simple_test_() ->
|
||||
{setup,
|
||||
fun setup/0,
|
||||
[
|
||||
?_assertMatch(
|
||||
[
|
||||
[
|
||||
{"first", [{"item", 1}]},
|
||||
{"second", [{"item", 2}]}
|
||||
]
|
||||
],
|
||||
yamerl_constr:file(?FILENAME, [{detailed_constr, false}])
|
||||
)
|
||||
]
|
||||
}.
|
||||
|
||||
detailed_test_() ->
|
||||
{setup,
|
||||
fun setup/0,
|
||||
[
|
||||
?_assertMatch(
|
||||
[
|
||||
{yamerl_doc,
|
||||
{yamerl_map,yamerl_node_map,"tag:yaml.org,2002:map",
|
||||
[{line,1},{column,1}],
|
||||
[{{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,1},{column,1}],
|
||||
"first"},
|
||||
{yamerl_map,yamerl_node_map,"tag:yaml.org,2002:map",
|
||||
[{line,1},{column,9}],
|
||||
[{{yamerl_str,yamerl_node_str,
|
||||
"tag:yaml.org,2002:str",
|
||||
[{line,1},{column,11}],
|
||||
"item"},
|
||||
{yamerl_int,yamerl_node_int,
|
||||
"tag:yaml.org,2002:int",
|
||||
[{line,1},{column,17}],
|
||||
1}}]}},
|
||||
{{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,2},{column,1}],
|
||||
"second"},
|
||||
{yamerl_map,yamerl_node_map,"tag:yaml.org,2002:map",
|
||||
[{line,2},{column,9}],
|
||||
[{{yamerl_str,yamerl_node_str,
|
||||
"tag:yaml.org,2002:str",
|
||||
[{line,2},{column,11}],
|
||||
"item"},
|
||||
{yamerl_int,yamerl_node_int,
|
||||
"tag:yaml.org,2002:int",
|
||||
[{line,2},{column,17}],
|
||||
2}}]}}]}}
|
||||
],
|
||||
yamerl_constr:file(?FILENAME, [{detailed_constr, true}])
|
||||
)
|
||||
]
|
||||
}.
|
135
test/construction/null.erl
Normal file
135
test/construction/null.erl
Normal file
@ -0,0 +1,135 @@
|
||||
-module(null).
|
||||
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
|
||||
-define(FILENAME, "test/construction/" ?MODULE_STRING ".yaml").
|
||||
|
||||
setup() ->
|
||||
application:start(yamerl).
|
||||
|
||||
schema_failsafe_simple_test_() ->
|
||||
{setup,
|
||||
fun setup/0,
|
||||
[
|
||||
?_assertMatch(
|
||||
[
|
||||
["~", "null", "Null", "NULL", "", "Not a null"]
|
||||
],
|
||||
yamerl_constr:file(?FILENAME,
|
||||
[{detailed_constr, false}, {schema, failsafe}])
|
||||
)
|
||||
]
|
||||
}.
|
||||
|
||||
schema_json_simple_test_() ->
|
||||
{setup,
|
||||
fun setup/0,
|
||||
[
|
||||
?_assertThrow(
|
||||
{yamerl_exception, [
|
||||
{yamerl_parsing_error,error, "Invalid string", 1, 3, not_a_string,
|
||||
{yamerl_scalar, 1, 3,
|
||||
{yamerl_tag, 1, 3, {non_specific, "?"}},
|
||||
flow, plain, "~"},
|
||||
[]}]},
|
||||
yamerl_constr:file(?FILENAME,
|
||||
[{detailed_constr, false}, {schema, json}])
|
||||
)
|
||||
]
|
||||
}.
|
||||
|
||||
schema_core_simple_test_() ->
|
||||
{setup,
|
||||
fun setup/0,
|
||||
[
|
||||
?_assertMatch(
|
||||
[
|
||||
[null, null, null, null, null, "Not a null"]
|
||||
],
|
||||
yamerl_constr:file(?FILENAME,
|
||||
[{detailed_constr, false}, {schema, core}])
|
||||
)
|
||||
]
|
||||
}.
|
||||
|
||||
schema_failsafe_detailed_test_() ->
|
||||
{setup,
|
||||
fun setup/0,
|
||||
[
|
||||
?_assertMatch(
|
||||
[
|
||||
{yamerl_doc,
|
||||
{yamerl_seq,yamerl_node_seq,"tag:yaml.org,2002:seq",
|
||||
[{line,1},{column,1}],
|
||||
[{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,1},{column,3}],
|
||||
"~"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,2},{column,3}],
|
||||
"null"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,3},{column,3}],
|
||||
"Null"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,4},{column,3}],
|
||||
"NULL"},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,5},{column,1}],
|
||||
""},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,7},{column,3}],
|
||||
"Not a null"}],
|
||||
6}}
|
||||
],
|
||||
yamerl_constr:file(?FILENAME,
|
||||
[{detailed_constr, true}, {schema, failsafe}])
|
||||
)
|
||||
]
|
||||
}.
|
||||
|
||||
schema_json_detailed_test_() ->
|
||||
{setup,
|
||||
fun setup/0,
|
||||
[
|
||||
?_assertThrow(
|
||||
{yamerl_exception, [
|
||||
{yamerl_parsing_error,error, "Invalid string", 1, 3, not_a_string,
|
||||
{yamerl_scalar, 1, 3,
|
||||
{yamerl_tag, 1, 3, {non_specific, "?"}},
|
||||
flow, plain, "~"},
|
||||
[]}]},
|
||||
yamerl_constr:file(?FILENAME,
|
||||
[{detailed_constr, true}, {schema, json}])
|
||||
)
|
||||
]
|
||||
}.
|
||||
|
||||
schema_core_detailed_test_() ->
|
||||
{setup,
|
||||
fun setup/0,
|
||||
[
|
||||
?_assertMatch(
|
||||
[
|
||||
{yamerl_doc,
|
||||
{yamerl_seq,yamerl_node_seq,"tag:yaml.org,2002:seq",
|
||||
[{line,1},{column,1}],
|
||||
[{yamerl_null,yamerl_node_null,"tag:yaml.org,2002:null",
|
||||
[{line,1},{column,3}]},
|
||||
{yamerl_null,yamerl_node_null,"tag:yaml.org,2002:null",
|
||||
[{line,2},{column,3}]},
|
||||
{yamerl_null,yamerl_node_null,"tag:yaml.org,2002:null",
|
||||
[{line,3},{column,3}]},
|
||||
{yamerl_null,yamerl_node_null,"tag:yaml.org,2002:null",
|
||||
[{line,4},{column,3}]},
|
||||
{yamerl_null,yamerl_node_null,"tag:yaml.org,2002:null",
|
||||
[{line,5},{column,1}]},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,7},{column,3}],
|
||||
"Not a null"}],
|
||||
6}}
|
||||
],
|
||||
yamerl_constr:file(?FILENAME,
|
||||
[{detailed_constr, true}, {schema, core}])
|
||||
)
|
||||
]
|
||||
}.
|
42
test/construction/null_json.erl
Normal file
42
test/construction/null_json.erl
Normal file
@ -0,0 +1,42 @@
|
||||
-module(null_json).
|
||||
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
|
||||
-define(FILENAME, "test/construction/" ?MODULE_STRING ".yaml").
|
||||
|
||||
setup() ->
|
||||
application:start(yamerl).
|
||||
|
||||
simple_test_() ->
|
||||
{setup,
|
||||
fun setup/0,
|
||||
[
|
||||
?_assertMatch(
|
||||
[
|
||||
[null]
|
||||
],
|
||||
yamerl_constr:file(?FILENAME,
|
||||
[{detailed_constr, false}, {schema, json}])
|
||||
)
|
||||
]
|
||||
}.
|
||||
|
||||
detailed_test_() ->
|
||||
{setup,
|
||||
fun setup/0,
|
||||
[
|
||||
?_assertMatch(
|
||||
[
|
||||
{yamerl_doc,
|
||||
{yamerl_seq,yamerl_node_seq,"tag:yaml.org,2002:seq",
|
||||
[{line,1},{column,1}],
|
||||
[{yamerl_null,yamerl_node_null_json,
|
||||
"tag:yaml.org,2002:null",
|
||||
[{line,1},{column,3}]}],
|
||||
1}}
|
||||
],
|
||||
yamerl_constr:file(?FILENAME,
|
||||
[{detailed_constr, true}, {schema, json}])
|
||||
)
|
||||
]
|
||||
}.
|
63
test/construction/seq.erl
Normal file
63
test/construction/seq.erl
Normal file
@ -0,0 +1,63 @@
|
||||
-module(seq).
|
||||
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
|
||||
-define(FILENAME, "test/construction/" ?MODULE_STRING ".yaml").
|
||||
|
||||
setup() ->
|
||||
application:start(yamerl).
|
||||
|
||||
simple_test_() ->
|
||||
{setup,
|
||||
fun setup/0,
|
||||
[
|
||||
?_assertMatch(
|
||||
[
|
||||
[
|
||||
[ "item", 1 ],
|
||||
[ "item", 2 ]
|
||||
]
|
||||
],
|
||||
yamerl_constr:file(?FILENAME, [{detailed_constr, false}])
|
||||
)
|
||||
]
|
||||
}.
|
||||
|
||||
detailed_test_() ->
|
||||
{setup,
|
||||
fun setup/0,
|
||||
[
|
||||
?_assertMatch(
|
||||
[
|
||||
{yamerl_doc,
|
||||
{yamerl_seq,yamerl_node_seq,"tag:yaml.org,2002:seq",
|
||||
[{line,1},{column,1}],
|
||||
[{yamerl_seq,yamerl_node_seq,"tag:yaml.org,2002:seq",
|
||||
[{line,1},{column,3}],
|
||||
[{yamerl_str,yamerl_node_str,
|
||||
"tag:yaml.org,2002:str",
|
||||
[{line,1},{column,5}],
|
||||
"item"},
|
||||
{yamerl_int,yamerl_node_int,
|
||||
"tag:yaml.org,2002:int",
|
||||
[{line,1},{column,11}],
|
||||
1}],
|
||||
2},
|
||||
{yamerl_seq,yamerl_node_seq,"tag:yaml.org,2002:seq",
|
||||
[{line,2},{column,3}],
|
||||
[{yamerl_str,yamerl_node_str,
|
||||
"tag:yaml.org,2002:str",
|
||||
[{line,2},{column,5}],
|
||||
"item"},
|
||||
{yamerl_int,yamerl_node_int,
|
||||
"tag:yaml.org,2002:int",
|
||||
[{line,2},{column,11}],
|
||||
2}],
|
||||
2}],
|
||||
2}
|
||||
}
|
||||
],
|
||||
yamerl_constr:file(?FILENAME, [{detailed_constr, true}])
|
||||
)
|
||||
]
|
||||
}.
|
69
test/construction/size.erl
Normal file
69
test/construction/size.erl
Normal file
@ -0,0 +1,69 @@
|
||||
-module(size).
|
||||
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
|
||||
-define(FILENAME, "test/construction/" ?MODULE_STRING ".yaml").
|
||||
|
||||
setup() ->
|
||||
application:start(yamerl),
|
||||
yamerl_app:set_param(node_mods, [yamerl_node_size]).
|
||||
|
||||
simple_test_() ->
|
||||
{setup,
|
||||
fun setup/0,
|
||||
[
|
||||
?_assertMatch(
|
||||
[
|
||||
[
|
||||
2000, 2000000, 2000000000, 2000000000000,
|
||||
2048, 2097152, 2147483648, 2199023255552,
|
||||
"Not a size"
|
||||
]
|
||||
],
|
||||
yamerl_constr:file(?FILENAME, [{detailed_constr, false}])
|
||||
)
|
||||
]
|
||||
}.
|
||||
|
||||
detailed_test_() ->
|
||||
{setup,
|
||||
fun setup/0,
|
||||
[
|
||||
?_assertMatch(
|
||||
[
|
||||
{yamerl_doc,
|
||||
{yamerl_seq,yamerl_node_seq,"tag:yaml.org,2002:seq",
|
||||
[{line,1},{column,1}],
|
||||
[{yamerl_int,yamerl_node_size,"tag:yamerl,2012:size",
|
||||
[{line,1},{column,3}],
|
||||
2000},
|
||||
{yamerl_int,yamerl_node_size,"tag:yamerl,2012:size",
|
||||
[{line,2},{column,3}],
|
||||
2000000},
|
||||
{yamerl_int,yamerl_node_size,"tag:yamerl,2012:size",
|
||||
[{line,3},{column,3}],
|
||||
2000000000},
|
||||
{yamerl_int,yamerl_node_size,"tag:yamerl,2012:size",
|
||||
[{line,4},{column,3}],
|
||||
2000000000000},
|
||||
{yamerl_int,yamerl_node_size,"tag:yamerl,2012:size",
|
||||
[{line,6},{column,3}],
|
||||
2048},
|
||||
{yamerl_int,yamerl_node_size,"tag:yamerl,2012:size",
|
||||
[{line,7},{column,3}],
|
||||
2097152},
|
||||
{yamerl_int,yamerl_node_size,"tag:yamerl,2012:size",
|
||||
[{line,8},{column,3}],
|
||||
2147483648},
|
||||
{yamerl_int,yamerl_node_size,"tag:yamerl,2012:size",
|
||||
[{line,9},{column,3}],
|
||||
2199023255552},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,11},{column,3}],
|
||||
"Not a size"}],
|
||||
9}}
|
||||
],
|
||||
yamerl_constr:file(?FILENAME, [{detailed_constr, true}])
|
||||
)
|
||||
]
|
||||
}.
|
110
test/construction/str.erl
Normal file
110
test/construction/str.erl
Normal file
@ -0,0 +1,110 @@
|
||||
-module(str).
|
||||
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
|
||||
-define(FILENAME, "test/construction/" ?MODULE_STRING ".yaml").
|
||||
|
||||
setup() ->
|
||||
application:start(yamerl).
|
||||
|
||||
list_simple_test_() ->
|
||||
{setup,
|
||||
fun setup/0,
|
||||
[
|
||||
?_assertMatch(
|
||||
[
|
||||
[$2, $\s, 8364] % "2 €"
|
||||
],
|
||||
yamerl_constr:file(?FILENAME, [{detailed_constr, false}])
|
||||
)
|
||||
]
|
||||
}.
|
||||
|
||||
list_detailed_test_() ->
|
||||
{setup,
|
||||
fun setup/0,
|
||||
[
|
||||
?_assertMatch(
|
||||
[
|
||||
{yamerl_doc,
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,1},{column,1}],
|
||||
[$2, $\s, 8364]} % "2 €"
|
||||
}
|
||||
],
|
||||
yamerl_constr:file(?FILENAME, [{detailed_constr, true}])
|
||||
)
|
||||
]
|
||||
}.
|
||||
|
||||
binary_simple_test_() ->
|
||||
{setup,
|
||||
fun setup/0,
|
||||
[
|
||||
?_assertMatch(
|
||||
[
|
||||
<<50,32,226,130,172>> % "2 €"
|
||||
],
|
||||
yamerl_constr:file(?FILENAME, [
|
||||
{detailed_constr, false},
|
||||
str_node_as_binary
|
||||
])
|
||||
)
|
||||
]
|
||||
}.
|
||||
|
||||
binary_detailed_test_() ->
|
||||
{setup,
|
||||
fun setup/0,
|
||||
[
|
||||
?_assertMatch(
|
||||
[
|
||||
{yamerl_doc,
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,1},{column,1}],
|
||||
<<50,32,226,130,172>>} % "2 €"
|
||||
}
|
||||
],
|
||||
yamerl_constr:file(?FILENAME, [
|
||||
{detailed_constr, true},
|
||||
str_node_as_binary
|
||||
])
|
||||
)
|
||||
]
|
||||
}.
|
||||
|
||||
binary_utf32be_simple_test_() ->
|
||||
{setup,
|
||||
fun setup/0,
|
||||
[
|
||||
?_assertMatch(
|
||||
[
|
||||
<<0,0,0,50, 0,0,0,32, 0,0,32,172>> % "2 €"
|
||||
],
|
||||
yamerl_constr:file(?FILENAME, [
|
||||
{detailed_constr, false},
|
||||
{str_node_as_binary, {utf32, big}}
|
||||
])
|
||||
)
|
||||
]
|
||||
}.
|
||||
|
||||
binary_utf32be_simple_detailed_test_() ->
|
||||
{setup,
|
||||
fun setup/0,
|
||||
[
|
||||
?_assertMatch(
|
||||
[
|
||||
{yamerl_doc,
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,1},{column,1}],
|
||||
<<0,0,0,50, 0,0,0,32, 0,0,32,172>>} % "2 €"
|
||||
}
|
||||
],
|
||||
yamerl_constr:file(?FILENAME, [
|
||||
{detailed_constr, true},
|
||||
{str_node_as_binary, {utf32, big}}
|
||||
])
|
||||
)
|
||||
]
|
||||
}.
|
54
test/construction/stream.erl
Normal file
54
test/construction/stream.erl
Normal file
@ -0,0 +1,54 @@
|
||||
-module(stream).
|
||||
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
|
||||
setup() ->
|
||||
application:start(yamerl).
|
||||
|
||||
simple_test_() ->
|
||||
{setup,
|
||||
fun setup/0,
|
||||
[
|
||||
?_assertMatch(
|
||||
["Hello!"],
|
||||
begin
|
||||
Stream_St1 = yamerl_constr:new("<stdin>"),
|
||||
{continue, Stream_St2} = yamerl_constr:next_chunk(Stream_St1,
|
||||
<<"He">>),
|
||||
{continue, Stream_St3} = yamerl_constr:next_chunk(Stream_St2,
|
||||
<<"ll">>),
|
||||
yamerl_constr:last_chunk(Stream_St3, <<"o!">>)
|
||||
end
|
||||
)
|
||||
]
|
||||
}.
|
||||
|
||||
detailed_test_() ->
|
||||
{setup,
|
||||
fun setup/0,
|
||||
[
|
||||
?_assertThrow(
|
||||
{yamerl_exception,
|
||||
[
|
||||
{yamerl_parsing_error, error,
|
||||
"Unexpected end-of-stream while parsing flow scalar",
|
||||
1, 8,
|
||||
unexpected_eos,
|
||||
{yamerl_scalar, 1, 1, {yamerl_tag, 1, 1, {non_specific, "!"}},
|
||||
flow, single_quoted,
|
||||
"Hello!"},
|
||||
[]
|
||||
}
|
||||
]
|
||||
},
|
||||
begin
|
||||
Stream_St1 = yamerl_constr:new("<stdin>"),
|
||||
{continue, Stream_St2} = yamerl_constr:next_chunk(Stream_St1,
|
||||
<<"'He">>),
|
||||
{continue, Stream_St3} = yamerl_constr:next_chunk(Stream_St2,
|
||||
<<"ll">>),
|
||||
yamerl_constr:last_chunk(Stream_St3, <<"o!">>)
|
||||
end
|
||||
)
|
||||
]
|
||||
}.
|
80
test/construction/timestamp.erl
Normal file
80
test/construction/timestamp.erl
Normal file
@ -0,0 +1,80 @@
|
||||
-module(timestamp).
|
||||
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
|
||||
-define(FILENAME, "test/construction/" ?MODULE_STRING ".yaml").
|
||||
|
||||
setup() ->
|
||||
application:start(yamerl),
|
||||
Node_Mods = yamerl_app:get_param(node_mods),
|
||||
yamerl_app:set_param(node_mods, [yamerl_node_timestamp]),
|
||||
Node_Mods.
|
||||
|
||||
teardown(Node_Mods) ->
|
||||
yamerl_app:set_param(node_mods, Node_Mods).
|
||||
|
||||
simple_test_() ->
|
||||
{setup,
|
||||
fun setup/0,
|
||||
fun teardown/1,
|
||||
[
|
||||
?_assertMatch(
|
||||
[
|
||||
[
|
||||
{{2011, 5, 26}, undefined},
|
||||
{undefined, {14,58,3}},
|
||||
{{2011, 5, 26}, {14,58,3}},
|
||||
{{2011, 5, 26}, {14,58,3}},
|
||||
{{2011, 5, 26}, {14,58,3}},
|
||||
"Not a timestamp"
|
||||
]
|
||||
],
|
||||
yamerl_constr:file(?FILENAME, [{detailed_constr, false}])
|
||||
)
|
||||
]
|
||||
}.
|
||||
|
||||
detailed_test_() ->
|
||||
{setup,
|
||||
fun setup/0,
|
||||
fun teardown/1,
|
||||
[
|
||||
?_assertMatch(
|
||||
[
|
||||
{yamerl_doc,
|
||||
{yamerl_seq,yamerl_node_seq,"tag:yaml.org,2002:seq",
|
||||
[{line,1},{column,1}],
|
||||
[{yamerl_timestamp,yamerl_node_timestamp,
|
||||
"tag:yamerl,2012:timestamp",
|
||||
[{line,1},{column,3}],
|
||||
2011,5,26,undefined,undefined,undefined,
|
||||
0,0},
|
||||
{yamerl_timestamp,yamerl_node_timestamp,
|
||||
"tag:yamerl,2012:timestamp",
|
||||
[{line,2},{column,3}],
|
||||
undefined,undefined,undefined,14,58,3,
|
||||
0,0},
|
||||
{yamerl_timestamp,yamerl_node_timestamp,
|
||||
"tag:yamerl,2012:timestamp",
|
||||
[{line,3},{column,3}],
|
||||
2011,5,26,14,58,3,
|
||||
0,0},
|
||||
{yamerl_timestamp,yamerl_node_timestamp,
|
||||
"tag:yamerl,2012:timestamp",
|
||||
[{line,4},{column,3}],
|
||||
2011,5,26,14,58,3,
|
||||
0,0},
|
||||
{yamerl_timestamp,yamerl_node_timestamp,
|
||||
"tag:yamerl,2012:timestamp",
|
||||
[{line,5},{column,3}],
|
||||
2011,5,26,14,58,3,
|
||||
0,0},
|
||||
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
|
||||
[{line,7},{column,3}],
|
||||
"Not a timestamp"}],
|
||||
6}}
|
||||
],
|
||||
yamerl_constr:file(?FILENAME, [{detailed_constr, true}])
|
||||
)
|
||||
]
|
||||
}.
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user