-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add spec file (Thanks @daurnimator!), more examples, new rockspec.
- Loading branch information
Showing
5 changed files
with
136 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
local F = require("F") | ||
|
||
local assert = assert | ||
local _ENV = {x = "foo"} | ||
function gee() | ||
assert("foo" == x) | ||
assert("foo" == F'{x}') | ||
end | ||
gee() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
local F = require("F") | ||
|
||
local f = 99 | ||
local c = (f-32)/9*5 | ||
|
||
print(F"{f} degrees Fahrenheit is {c:%.2f} degrees Celsius") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
|
||
local F = require("F") | ||
|
||
local u = "Hello" | ||
|
||
local function f() | ||
local w = "World" | ||
return function() | ||
local gobo = "GOBO" | ||
print(u .. " " .. w) | ||
print(F"{u} {w} of {gobo}") | ||
end | ||
end | ||
|
||
f()() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package = "f-strings" | ||
version = "0.2-1" | ||
source = { | ||
url = "git://github.com/hishamhm/f-strings", | ||
tag = "v0.2", | ||
} | ||
description = { | ||
summary = [[String interpolation for Lua.]], | ||
detailed = [[ | ||
String interpolation for Lua, inspired by f-strings, | ||
a form of string interpolation in Python 3.6. | ||
It allows you to interpolate variables in strings | ||
(including local variables) using the syntax: | ||
str = F"The value of x is {x} and the value of y is {y:%.2f}." | ||
]], | ||
homepage = "http://github.com/hishamhm/f-strings", | ||
license = "MIT" | ||
} | ||
dependencies = {} | ||
build = { | ||
type = "builtin", | ||
modules = { | ||
F = "F.lua", | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
describe("string interpolation", function() | ||
local F = require "F" | ||
local assert = assert | ||
it("works with literals", function() | ||
assert.same("foo", F'{"foo"}') | ||
end) | ||
it("works with locals", function() | ||
do | ||
local x = "foo" | ||
assert.same("foo", F'{x}') | ||
end | ||
end) | ||
it("works with referenced upvalues", function() | ||
do | ||
local x = "foo" | ||
(function() | ||
assert.same("foo", x) -- reference the upvalue | ||
assert.same("foo", F'{x}') | ||
end)() | ||
end | ||
end) | ||
it("fails with unreferenced upvalues", function() | ||
do | ||
(function() | ||
local x = "foo" | ||
return function() | ||
assert.not_same("foo", F'{x}') | ||
end | ||
end)()() | ||
end | ||
end); | ||
(_VERSION == "Lua 5.1" and it or pending)("works with setfenv'd functions", function() | ||
setfenv(1, {x = "foo"}) | ||
assert.same("foo", x) | ||
assert.same("foo", F'{x}') | ||
end); | ||
(_VERSION == "Lua 5.1" and pending or it)("works with _ENV scopes", function() | ||
do | ||
local _ENV = {x = "foo"} | ||
assert.same("foo", F'{x}') | ||
end | ||
end); | ||
(_VERSION == "Lua 5.1" and pending or it)("fails with _ENV as an unreferenced upvalue", function() | ||
do | ||
local _ENV = {x = "foo"} | ||
(function() | ||
assert.not_same("foo", F'{x}') | ||
end)() | ||
end | ||
end); | ||
(_VERSION == "Lua 5.1" and pending or it)("works with _ENV as a referenced upvalue", function() | ||
do | ||
local _ENV = {x = "foo"} | ||
(function() | ||
assert.same("foo", x) -- reference the upvalue | ||
assert.same("foo", F'{x}') | ||
end)() | ||
end | ||
end); | ||
(_VERSION == "Lua 5.1" and pending or it)("fails with unreferenced upvalue in custom _ENV", function() | ||
do | ||
(function() | ||
local _ENV = {x = "foo"} | ||
return function() | ||
assert.not_same("foo", F'{x}') | ||
end | ||
end)()() | ||
end | ||
end); | ||
(_VERSION == "Lua 5.1" and pending or it)("works with referenced upvalue in custom _ENV", function() | ||
do | ||
(function() | ||
local _ENV = {x = "foo"} | ||
return function() | ||
assert.same("foo", x) -- reference the upvalue | ||
assert.same("foo", F'{x}') | ||
end | ||
end)()() | ||
end | ||
end) | ||
end) |