Skip to content

Commit eaa9f21

Browse files
tobiclaude
andcommitted
Add lax and YJIT liquid-spec adapters
- 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 <noreply@anthropic.com>
1 parent ccd05e8 commit eaa9f21

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed

spec/ruby_liquid_lax.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# frozen_string_literal: true
2+
3+
# Liquid Spec Adapter for Shopify/liquid with lax parsing mode
4+
#
5+
# Run with: bundle exec liquid-spec run spec/ruby_liquid_lax.rb
6+
7+
$LOAD_PATH.unshift(File.expand_path('../lib', __dir__))
8+
require 'liquid'
9+
10+
LiquidSpec.configure do |config|
11+
config.features = [:core, :lax_parsing]
12+
end
13+
14+
# Compile a template string into a Liquid::Template
15+
LiquidSpec.compile do |ctx, source, options|
16+
# Force lax mode
17+
options = options.merge(error_mode: :lax)
18+
Liquid::Template.parse(source, **options)
19+
end
20+
21+
# Render a compiled template with the given context
22+
LiquidSpec.render do |ctx, template, assigns, options|
23+
registers = Liquid::Registers.new(options[:registers] || {})
24+
25+
context = Liquid::Context.build(
26+
static_environments: assigns,
27+
registers: registers,
28+
rethrow_errors: options[:strict_errors],
29+
)
30+
31+
context.exception_renderer = options[:exception_renderer] if options[:exception_renderer]
32+
33+
template.render(context)
34+
end

spec/ruby_liquid_yjit.rb

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# frozen_string_literal: true
2+
3+
# Liquid Spec Adapter for Shopify/liquid with YJIT + strict mode + ActiveSupport
4+
#
5+
# Run with: bundle exec liquid-spec run spec/ruby_liquid_yjit.rb
6+
7+
$LOAD_PATH.unshift(File.expand_path('../lib', __dir__))
8+
9+
# Enable YJIT if available
10+
if defined?(RubyVM::YJIT) && RubyVM::YJIT.respond_to?(:enable)
11+
RubyVM::YJIT.enable
12+
end
13+
14+
require 'active_support/all'
15+
require 'liquid'
16+
17+
LiquidSpec.configure do |config|
18+
config.features = [:core, :activesupport]
19+
end
20+
21+
# Compile a template string into a Liquid::Template
22+
LiquidSpec.compile do |ctx, source, options|
23+
# Force strict mode
24+
options = { error_mode: :strict }.merge(options)
25+
Liquid::Template.parse(source, **options)
26+
end
27+
28+
# Render a compiled template with the given context
29+
LiquidSpec.render do |ctx, template, assigns, options|
30+
registers = Liquid::Registers.new(options[:registers] || {})
31+
32+
context = Liquid::Context.build(
33+
static_environments: assigns,
34+
registers: registers,
35+
rethrow_errors: options[:strict_errors],
36+
)
37+
38+
context.exception_renderer = options[:exception_renderer] if options[:exception_renderer]
39+
40+
template.render(context)
41+
end

0 commit comments

Comments
 (0)