diff --git a/lib/extism/plugin.rb b/lib/extism/plugin.rb index 6158e1a..45edf61 100644 --- a/lib/extism/plugin.rb +++ b/lib/extism/plugin.rb @@ -47,7 +47,7 @@ def initialize(wasm, environment: nil, functions: [], wasi: false, config: nil) end $PLUGINS[object_id] = { plugin: @plugin } ObjectSpace.define_finalizer(self, $FREE_PLUGIN) - return unless !config.nil? and @plugin.null? + return if config.nil? or @plugin.null? s = JSON.generate(config) ptr = FFI::MemoryPointer.from_string(s) diff --git a/test/test_extism.rb b/test/test_extism.rb index 3b3d130..d18e221 100644 --- a/test/test_extism.rb +++ b/test/test_extism.rb @@ -64,7 +64,7 @@ def test_that_it_has_a_version_number end def test_plugin_call - plugin = Extism::Plugin.new(vowels_manifest) + plugin = Extism::Plugin.new(vowels_manifest, config: { vowels: 'aeiouyAEIOUY' }) res = JSON.parse(plugin.call('count_vowels', 'this is a test')) assert_equal res['count'], 4 res = JSON.parse(plugin.call('count_vowels', 'this is a test again')) @@ -73,6 +73,9 @@ def test_plugin_call assert_equal res['count'], 6 res = JSON.parse(plugin.call('count_vowels', '🌎hello🌎world🌎')) assert_equal res['count'], 3 + res = JSON.parse(plugin.call('count_vowels', 'does y count?')) + assert_equal res['count'], 5 + assert_equal res['vowels'], 'aeiouyAEIOUY' end def test_can_free_plugin