From eaa9f215bf90d05ef5113055dfc42e85e991dd3c Mon Sep 17 00:00:00 2001 From: Tobi Lutke Date: Mon, 5 Jan 2026 15:11:29 -1000 Subject: [PATCH] Add lax and YJIT liquid-spec adapters MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - ruby_liquid_lax.rb: Tests lax parsing mode with :lax_parsing feature - ruby_liquid_yjit.rb: Tests YJIT + strict mode + ActiveSupport Matrix results: 4483 matched, 18 different (lax edge cases), 61 skipped 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- spec/ruby_liquid_lax.rb | 34 +++++++++++++++++++++++++++++++++ spec/ruby_liquid_yjit.rb | 41 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 spec/ruby_liquid_lax.rb create mode 100644 spec/ruby_liquid_yjit.rb diff --git a/spec/ruby_liquid_lax.rb b/spec/ruby_liquid_lax.rb new file mode 100644 index 00000000..b9fc497a --- /dev/null +++ b/spec/ruby_liquid_lax.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +# Liquid Spec Adapter for Shopify/liquid with lax parsing mode +# +# Run with: bundle exec liquid-spec run spec/ruby_liquid_lax.rb + +$LOAD_PATH.unshift(File.expand_path('../lib', __dir__)) +require 'liquid' + +LiquidSpec.configure do |config| + config.features = [:core, :lax_parsing] +end + +# Compile a template string into a Liquid::Template +LiquidSpec.compile do |ctx, source, options| + # Force lax mode + options = options.merge(error_mode: :lax) + Liquid::Template.parse(source, **options) +end + +# Render a compiled template with the given context +LiquidSpec.render do |ctx, template, assigns, options| + registers = Liquid::Registers.new(options[:registers] || {}) + + context = Liquid::Context.build( + static_environments: assigns, + registers: registers, + rethrow_errors: options[:strict_errors], + ) + + context.exception_renderer = options[:exception_renderer] if options[:exception_renderer] + + template.render(context) +end diff --git a/spec/ruby_liquid_yjit.rb b/spec/ruby_liquid_yjit.rb new file mode 100644 index 00000000..e34e0abb --- /dev/null +++ b/spec/ruby_liquid_yjit.rb @@ -0,0 +1,41 @@ +# frozen_string_literal: true + +# Liquid Spec Adapter for Shopify/liquid with YJIT + strict mode + ActiveSupport +# +# Run with: bundle exec liquid-spec run spec/ruby_liquid_yjit.rb + +$LOAD_PATH.unshift(File.expand_path('../lib', __dir__)) + +# Enable YJIT if available +if defined?(RubyVM::YJIT) && RubyVM::YJIT.respond_to?(:enable) + RubyVM::YJIT.enable +end + +require 'active_support/all' +require 'liquid' + +LiquidSpec.configure do |config| + config.features = [:core, :activesupport] +end + +# Compile a template string into a Liquid::Template +LiquidSpec.compile do |ctx, source, options| + # Force strict mode + options = { error_mode: :strict }.merge(options) + Liquid::Template.parse(source, **options) +end + +# Render a compiled template with the given context +LiquidSpec.render do |ctx, template, assigns, options| + registers = Liquid::Registers.new(options[:registers] || {}) + + context = Liquid::Context.build( + static_environments: assigns, + registers: registers, + rethrow_errors: options[:strict_errors], + ) + + context.exception_renderer = options[:exception_renderer] if options[:exception_renderer] + + template.render(context) +end