Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

A test suite for the Liquid template language.

License

NotificationsYou must be signed in to change notification settings

jg-rp/golden-liquid

Repository files navigation

A test suite forLiquid, the safe, customer-facing template language for flexible web apps.

Intended for situations where template authors are untrusted and, perhaps, not software developers, Liquid is deliberately both restrictive and forgiving. It is restrictive in that Liquid expressions are somewhat limited compared to those found in other template languages, and forgiving in the way it automatically coerces data types and handles undefined variables.

The tests defined ingolden_liquid.json attempt to cover many of Liquid's limitations, as well as the behavior of all standard tags and filters.

Standard Liquid

For our purposes "standard" Liquid is the one describedhere withShopify/Liquid being the reference implementation. Not to be confused with the extended variation of Liquid used for Shopify stores.

All tests pass with Liquid version 5.8.1 and Ruby 3. Someround filter test cases fail with Ruby 2.7 due to changes with Ruby's BigDecimal library (see issue#1590). If you have Ruby installed, you can run the test suite against the reference implementation by cloning this repository and running the following commands.

cd liquidbundle installbundle exec ruby golden_liquid.rb

Test File Schema

Ingolden_liquid.json tests are grouped. Each group has a name and an array of test cases. Including a version number,golden_liquid.json looks like this.

{"version":"0.24.0","test_groups": [        {"name":"liquid.golden.abs_filter","tests": [                {"name":"negative float","template":"{{ -5.4 | abs }}","want":"5.4","context": {},"partials": {},"error":false,"strict":false                },..            ]        },..    ]}

golden_liquid.yaml is the same test suite in YAML format.

version:0.23.0test_groups:  -name:liquid.golden.abs_filtertests:      -name:negative floattemplate:"{{ -5.4 | abs }}"want:"5.4"context:{}partials:{}error:falsestrict:false

For each test case:

  • name is descriptive name for the test case. Together with the group name it should uniquely identify the test case.
  • template is Liquid source text as a string.
  • want is the expected result of rendering the template with the associated context.
  • context is a JSON object mapping strings to arbitrary, possibly nested, strings, numbers, arrays, objects and booleans. These are the variables that the associated template should be rendered with.
  • partials is a JSON object mapping strings to strings. You can think of it as a mock file system for testing{% include %} and{% render %}.
  • error is a Boolean indicating if the test case should raise/throw an exception/error.
  • strict is a Boolean indicating if the test should be rendered in "strict mode", if the target environment has a strict mode.

Results Summary

This table summarizes the results of running version 0.24.0 of this test suit against the five Liquid engines with runners included in this repository.

EngineVersionPassedFailed
Shopify/Liquid5.8.110100
LiquidJS**10.21.0720290
liquidpy0.8.2451559
LiquidScript1.8.2907103
Python Liquid2.0.0 (unreleased)10100
Python Liquid20.3.091694

** It's worth noting that many, but not all, of the failed test cases for LiquidJS are due to the way it handles excess and/or unexpected filter arguments, and its lack of distinct float and int types.

More Information

golden_liquid.json andgolden_liquid.yaml are currently generated fromthese files in thePython Liquid repository. The plan is to move these source files (or some equivalent files) to this repository, so we might add test cases for behavior that Python Liquid chooses not to implement.

In the mean time, be sure to keep an eye on Python Liquid'sknown issues page andissue tracker.

About

A test suite for the Liquid template language.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

[8]ページ先頭

©2009-2025 Movatter.jp