-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Refactored tests into a scenario (easier to automatically launch) - Added thumbnail.png
- Loading branch information
Showing
18 changed files
with
158 additions
and
47 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
This file was deleted.
Oops, something went wrong.
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
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,82 @@ | ||
local createElement = require("__react__.lib.core").createElement | ||
|
||
-- static vars | ||
local MODE_TEXT = 0 | ||
local MODE_OPEN_TAG = 1 | ||
local MODE_CLOSE_TAG = 2 | ||
|
||
local function assert(condition, msg) | ||
if not condition then | ||
log(msg) | ||
end | ||
end | ||
|
||
local function lsx(s, fields) | ||
-- Stack of nested tags. Start with a fake top node. The actual top virtual | ||
-- node would become the first child of this node. We know this element is | ||
-- going to be invalid, so we ignore the param type mismatch. | ||
---@diagnostic disable-next-line: param-type-mismatch | ||
local stack = { createElement(nil) } | ||
|
||
-- current parsing mode | ||
local mode = MODE_TEXT | ||
|
||
-- Read and return the next word from the string, starting at position i. If | ||
-- the string is empty - return the corresponding placeholder field. | ||
local function readToken(str, i, pattern, field) | ||
str = str:sub(i) | ||
if #str == 0 then | ||
return str, field | ||
end | ||
local _, stop, capture = str:find(pattern) | ||
return str:sub(stop + 1), capture | ||
end | ||
|
||
while #s > 0 do | ||
local val | ||
s = s:gsub("^%s+", "") | ||
if mode == MODE_TEXT then | ||
if s:sub(1,1) == "<" then | ||
if s:sub(2,2) == "/" then | ||
s = readToken(s, 3, "(%w+)", fields) | ||
mode = MODE_CLOSE_TAG | ||
else | ||
s, val = readToken(s, 2, "(%w+)", fields) | ||
stack[#stack + 1] = createElement(val, {}) | ||
mode = MODE_OPEN_TAG | ||
end | ||
else | ||
s, val = readToken(s, 1, "([^<]+)", "") | ||
table.insert(stack[#stack].children, val) | ||
end | ||
elseif mode == MODE_OPEN_TAG then | ||
if s:sub(1,1) == "/" and s:sub(2,2) == ">" then | ||
table.insert(stack[#stack - 1].children, table.remove(stack)) | ||
mode = MODE_TEXT | ||
s = s:sub(3) | ||
elseif s:sub(1,1) == ">" then | ||
mode = MODE_TEXT | ||
s = s:sub(2) | ||
else | ||
s, val = readToken(s, 1, "([%w_-]+)=", "") | ||
assert(val ~= nil, "Invalid tag name") | ||
local propName = val | ||
s, val = readToken(s, 1, '"([^"]*)"', fields) | ||
stack[#stack].props[propName] = val | ||
end | ||
elseif mode == MODE_CLOSE_TAG then | ||
table.insert(stack[#stack - 1].children, table.remove(stack)) | ||
s = s:sub(2) | ||
mode = MODE_TEXT | ||
end | ||
end | ||
if mode == MODE_TEXT then | ||
table.insert(stack[#stack].children, fields) | ||
end | ||
return stack[1].children[1] | ||
end | ||
|
||
|
||
return { | ||
lsx = lsx | ||
} |
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
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,5 @@ | ||
-- https://github.com/justarandomgeek/vscode-factoriomod-debug/blob/aa61fe5e3782ed0b8914caa1ac9986f985000fb0/doc/debugapi.md#detecting-debugging | ||
if script.active_mods["gvv"] then require("__gvv__.gvv")() end | ||
|
||
-- Load the test suite | ||
require("init") |
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,4 @@ | ||
{ | ||
"multiplayer-compatible": true, | ||
"order": "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 @@ | ||
{} |
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
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,2 @@ | ||
scenario-name=Unit Tests | ||
description=Your task is to test the React library for Factorio.\n\nThis is [font=default-bold]definitely not[/font] the intended way of playing Factorio. |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,12 @@ | ||
local React = require("__react__.react") | ||
|
||
local function Test(props) | ||
local player = props.player | ||
|
||
return React.lsx([[<frame> | ||
<label caption="This was rendered by LSX" /> | ||
<label caption="Hello, ${name}!" /> | ||
</frame>]], { name = player.name }) | ||
end | ||
|
||
return Test |
File renamed without changes.
This file was deleted.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.