aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/socket_cursor.js8
-rw-r--r--tests/socket_fetch.js8
-rw-r--r--tests/space_comb.js24
-rw-r--r--tests/space_file.js14
-rw-r--r--tests/space_fromfetch.js9
-rw-r--r--tests/space_search.js16
-rw-r--r--tests/space_subsection.js10
7 files changed, 89 insertions, 0 deletions
diff --git a/tests/socket_cursor.js b/tests/socket_cursor.js
new file mode 100644
index 0000000..e9e4df7
--- /dev/null
+++ b/tests/socket_cursor.js
@@ -0,0 +1,8 @@
+// Tests Socket.cursor and Socket.on('cursor')
+
+Socket = require('../socket');
+
+world = new Socket();
+
+world.on('open', ()=>{world.cursor([22,23])});
+world.on('cursor', (locs, send)=>{console.log(locs,send)});
diff --git a/tests/socket_fetch.js b/tests/socket_fetch.js
new file mode 100644
index 0000000..b558f89
--- /dev/null
+++ b/tests/socket_fetch.js
@@ -0,0 +1,8 @@
+// Tests Socket.fetch and Socket.on('fetch')
+const Socket = require('../socket');
+
+let world = new Socket();
+
+world.on('open', () => {world.fetch([[10,10,10,10]])});
+
+world.on('fetch', (tiles) => {console.log(tiles);})
diff --git a/tests/space_comb.js b/tests/space_comb.js
new file mode 100644
index 0000000..1cde721
--- /dev/null
+++ b/tests/space_comb.js
@@ -0,0 +1,24 @@
+// Tests space.comb()
+
+const Space = require('../space');
+
+newspace = new Space();
+newspace.adhoc('\
+line1\n\
+&&&&transparency&&&&\n\
+\n\
+afterempty\n')
+
+otherspace = new Space();
+otherspace.adhoc('\
+&&&transparency&&&\n\
+testline');
+
+function add(char1,char2){
+ if (char1 == '') return char2;
+ else return char1;
+}
+
+otherspace.comb(newspace, add, [0,0]);
+
+console.log(otherspace.print());
diff --git a/tests/space_file.js b/tests/space_file.js
new file mode 100644
index 0000000..572214e
--- /dev/null
+++ b/tests/space_file.js
@@ -0,0 +1,14 @@
+// Tests Space.{to,from}file
+const Space = require('../space')
+
+text = new Space();
+
+text.adhoc('\
+line of text\n\
+other&&\\\\&&line of text\n\
+\n\
+final\n');
+
+text.tofile('local')
+text.fromfile('local')
+console.log(text.print()); //Should be losslessly transmitted, and local contains a copy
diff --git a/tests/space_fromfetch.js b/tests/space_fromfetch.js
new file mode 100644
index 0000000..67b41cc
--- /dev/null
+++ b/tests/space_fromfetch.js
@@ -0,0 +1,9 @@
+// Tets Space.fromfetch
+const Space = require('../space')
+
+newspace = new Space()
+
+newspace.fromfetch({"4,2": {"content": " hhhhhhhh k hone ns ", "properties": {"writability": null, "cell_props": {}}}},[4,2,4,2],conform=false);
+// Straight from a real tileUpdate
+
+console.log(newspace.data); //Should be an array of arrays of chars, representing the content of "content" above.
diff --git a/tests/space_search.js b/tests/space_search.js
new file mode 100644
index 0000000..14ec174
--- /dev/null
+++ b/tests/space_search.js
@@ -0,0 +1,16 @@
+// Tests space.search
+
+const Space = require('../space')
+
+let text = new Space();
+text.adhoc('\
+\n\
+ jarvis\n\
+ jarvis\n\
+ jarvis \
+');
+
+let line = new Space();
+line.adhoc('jarvis');
+
+console.log(text.search(line))
diff --git a/tests/space_subsection.js b/tests/space_subsection.js
new file mode 100644
index 0000000..b30b7e1
--- /dev/null
+++ b/tests/space_subsection.js
@@ -0,0 +1,10 @@
+// Tests Space.subsection()
+const Space = require('../space');
+
+newspace = new Space();
+newspace.adhoc('\
+line\n\
+\n\
+long long long line\
+');
+console.log(newspace.subsection([1,1,2,10]));