aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-03-06 11:00:22 +0100
committerBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-03-06 11:00:22 +0100
commitc3c1ab50646165c0e43784acb30a353dc5b40d12 (patch)
tree81d8a0941f67330fa872d19f017f414f99b0ee0d
parentd792a7dad54039074890d9d379eec8676cb9fa5a (diff)
downloadfengari-c3c1ab50646165c0e43784acb30a353dc5b40d12.tar.gz
fengari-c3c1ab50646165c0e43784acb30a353dc5b40d12.tar.bz2
fengari-c3c1ab50646165c0e43784acb30a353dc5b40d12.zip
string.upper/lower
-rw-r--r--README.md4
-rw-r--r--src/lstrlib.js16
-rw-r--r--tests/lstrlib.js37
3 files changed, 53 insertions, 4 deletions
diff --git a/README.md b/README.md
index a6e11df..8a1ba65 100644
--- a/README.md
+++ b/README.md
@@ -211,13 +211,14 @@
- [ ] String
- [x] string.char
- [x] string.len
+ - [x] string.lower
+ - [x] string.upper
- [ ] string.byte
- [ ] string.dump
- [ ] string.find
- [ ] string.format
- [ ] string.gmatch
- [ ] string.gsub
- - [ ] string.lower
- [ ] string.match
- [ ] string.pack
- [ ] string.packsize
@@ -225,7 +226,6 @@
- [ ] string.reverse
- [ ] string.sub
- [ ] string.unpack
- - [ ] string.upper
- [ ] Package
- [ ] os
- [ ] io
diff --git a/src/lstrlib.js b/src/lstrlib.js
index 69f634d..96a33f5 100644
--- a/src/lstrlib.js
+++ b/src/lstrlib.js
@@ -25,9 +25,21 @@ const str_char = function(L) {
return 1;
};
+const str_lower = function(L) {
+ lapi.lua_pushstring(L, lauxlib.luaL_checkstring(L, 1).toLowerCase());
+ return 1;
+};
+
+const str_upper = function(L) {
+ lapi.lua_pushstring(L, lauxlib.luaL_checkstring(L, 1).toUpperCase());
+ return 1;
+};
+
const strlib = {
- "len": str_len,
- "char": str_char
+ "char": str_char,
+ "len": str_len,
+ "lower": str_lower,
+ "upper": str_upper
};
const createmetatable = function(L) {
diff --git a/tests/lstrlib.js b/tests/lstrlib.js
index 494b881..7120525 100644
--- a/tests/lstrlib.js
+++ b/tests/lstrlib.js
@@ -78,4 +78,41 @@ test('string.char', function (t) {
"hello",
"Correct element(s) on the stack"
);
+});
+
+
+test('string.upper, string.lower', function (t) {
+ let luaCode = `
+ return string.upper("hello"), string.lower("HELLO")
+ `, L;
+
+ t.plan(4);
+
+ t.doesNotThrow(function () {
+
+ L = lauxlib.luaL_newstate();
+
+ linit.luaL_openlibs(L);
+
+ lauxlib.luaL_loadstring(L, luaCode);
+
+ }, "Lua program loaded without error");
+
+ t.doesNotThrow(function () {
+
+ lapi.lua_call(L, 0, -1);
+
+ }, "Lua program ran without error");
+
+ t.strictEqual(
+ lapi.lua_tostring(L, -2),
+ "HELLO",
+ "Correct element(s) on the stack"
+ );
+
+ t.strictEqual(
+ lapi.lua_tostring(L, -1),
+ "hello",
+ "Correct element(s) on the stack"
+ );
}); \ No newline at end of file