local function id(value) return value end
local paren_literal = ("ab"):find(id("b"))
print("paren literal receiver: " .. tostring(paren_literal == 2))
local constructor = ({ f = function(self, x) return x end }):f(id("q"))
print("constructor receiver: " .. tostring(constructor == "q"))
local paren_call = (id("ab")):find(id("b"))
print("parenthesized call receiver: " .. tostring(paren_call == 2))
local concat = ("a" .. "b"):find(id("b"))
print("concat receiver: " .. tostring(concat == 2))
local subject = "ab"
local plain = subject:find(id("b"))
print("plain name receiver: " .. tostring(plain == 2))
local holder = { s = "ab", [1] = "ab" }
print("field receiver: " .. tostring(holder.s:find(id("b")) == 2))
print("index receiver: " .. tostring(holder[1]:find(id("b")) == 2))
print("two call args: " .. tostring(("abc"):find(id("b"), id(1)) == 2))
print("nested call arg: " .. tostring(("ab"):find(id(("b"):sub(id(1)))) == 2))
local direct = (id(function(x) return x end))(id("v"))
print("parenthesized callee: " .. tostring(direct == "v"))
local function forward(...) return ("ab"):find(...) end
print("vararg arguments: " .. tostring(forward("b") == 2))
local function make(x) return function(y) return x .. tostring(y) end end
local function one() return 1 end
local methods = { make = function(self) return function(y) return y end end }
print("call result as callee: " .. tostring(make("a")(id("b")) == "ab"))
print("unparenthesized call receiver: " .. tostring(id("ab"):find(id("b")) == 2))
print("method result as callee: " .. tostring(methods:make()(id("ok")) == "ok"))
print("dynamic inner call: " .. tostring(make(one())(id(2)) == "12"))
local callables = { [1] = function(y) return y end }
print("indexed callee: " .. tostring(callables[1]("x") == "x"))
print("indexed callee chain: " .. tostring(callables[1](id("y")) == "y"))