Skip to content

Commit

Permalink
Add basic testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Sollace committed Dec 3, 2020
1 parent cf14a87 commit fbd422b
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
27 changes: 27 additions & 0 deletions test/input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"texture": {"w": 64, "h": 64},
"locals": {
"x": 0,
"y": 0,
"z": 0
},
"right": {
"texture": {"u": 12, "v": 16},
"offset": ["#x", "#y", "#z"],
"cubes": [
{ "from": [-4, -8, -1], "size": [2, 2, 2] },
{ "from": [-3.5, -8.49, -1.001], "size": [1, 1, 1], "texture": {"u": 0, "v": 3} },
{ "from": [-2.998, -8.49, -2.001], "size": [1, 1, 1], "texture": {"u": 0, "v": 5} }
]
},
"left": {
"texture": {"u": 12, "v": 16},
"offset": ["#x", "#y", "#z"],
"mirror": true,
"cubes": [
{ "from": [2, -8, -1], "size": [2, 2, 2] },
{ "from": [2.5, -8.49, -1.001], "size": [1, 1, 1], "texture": {"u": 0, "v": 3} },
{ "from": [1.998, -8.49, -2.001], "size": [1, 1, 1], "texture": {"u": 0, "v": 5} }
]
}
}
60 changes: 60 additions & 0 deletions test/test.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-type">
<script type="text/javascript" src="../src/obj_utils.js"></script>
<script type="text/javascript" src="../src/incomplete.js"></script>
<script type="text/javascript" src="../src/mson_loader.js"></script>
<script type="text/javascript" src="../src/fixtures.js"></script>
<script type="text/javascript" src="../src/mson_vanilla.js"></script>
<script type="text/javascript" src="../src/mson_more.js"></script>
<style>
html, body {
height: 100%;
width: 100%;
padding: 0;
margin: 0;
}
div {
height: 100%;
display: flex;
flex-direction: column;
}
textarea {
flex-grow: 1;
}
</style>
</head>
<body>
<div>
<input id="model_name" type="text"></input>
<textarea id="model_input"></textarea>
<button id="add_model">Add File</button>
<button id="get_model">Get Model</button>
<textarea id="output"></textarea>
</div>
<script type="text/javascript">
const modelNameIn = document.body.querySelector('#model_name');
const input = document.body.querySelector('#model_input');
const output = document.body.querySelector('#output');
let loader = Mson.createLoader();
function handled(func) {
try {
func();
} catch (e) {
output.value = e;
console.error(e);
}
}
document.body.querySelector('#add_model').addEventListener('click', () => {
handled(() => loader.addFile(modelNameIn.value, input.value));
});
document.body.querySelector('#get_model').addEventListener('click', () => {
handled(() => output.value = JSON.stringify(loader.getModel(modelNameIn.value), null, ' '));
});
// Damn coRs
// fetch('input.json').then(a => a.text()).then(a => input.value = a);

</script>
</body>
</html>

0 comments on commit fbd422b

Please sign in to comment.