Martin Dørum pirms 3 gadiem
vecāks
revīzija
9e6484754f
7 mainītis faili ar 95 papildinājumiem un 0 dzēšanām
  1. 3
    0
      .gitmodules
  2. 3
    0
      test/.gitignore
  3. 5
    0
      test/build.bx
  4. 1
    0
      test/snow
  5. 3
    0
      test/src/main.c
  6. 38
    0
      test/src/namespace.t.c
  7. 42
    0
      test/src/strset.t.c

+ 3
- 0
.gitmodules Parādīt failu

@@ -0,0 +1,3 @@
[submodule "test/snow"]
path = test/snow
url = git@github.com:mortie/snow.git

+ 3
- 0
test/.gitignore Parādīt failu

@@ -0,0 +1,3 @@
/.cache
/bx-out
/compile_commands.json

+ 5
- 0
test/build.bx Parādīt failu

@@ -0,0 +1,5 @@
files := src ../lib
includes := snow ../include/lang2
defines := SNOW_ENABLED
sanitizers := address
cflags := -g -O3

+ 1
- 0
test/snow

@@ -0,0 +1 @@
Subproject commit 54362df837dee70cd6e22c7cd1ef3c6dfea47122

+ 3
- 0
test/src/main.c Parādīt failu

@@ -0,0 +1,3 @@
#include <snow/snow.h>

snow_main();

+ 38
- 0
test/src/namespace.t.c Parādīt failu

@@ -0,0 +1,38 @@
#include "vm/vm.h"

#include <snow/snow.h>

describe(l2_vm_namespace) {
struct l2_vm_value val = {0};

after_each() {
free(val.data);
val.data = NULL;
}

test("basic functionality") {
l2_vm_namespace_set(&val, 100, 50);
l2_vm_namespace_set(&val, 30, 600);
asserteq(l2_vm_namespace_get(&val, 100), 50);
asserteq(l2_vm_namespace_get(&val, 30), 600);
}

it("handles duplicates") {
l2_vm_namespace_set(&val, 536, 600);
l2_vm_namespace_set(&val, 100, 400);
l2_vm_namespace_set(&val, 536, 45);
asserteq(l2_vm_namespace_get(&val, 100), 400);
asserteq(l2_vm_namespace_get(&val, 536), 45);
}

it("handles a whole bunch of values") {
for (int i = 1; i < 500; ++i) {
l2_vm_namespace_set(&val, i, i + 50);
asserteq(l2_vm_namespace_get(&val, i), i + 50);
}

for (int i = 1; i < 500; ++i) {
asserteq(l2_vm_namespace_get(&val, i), i + 50);
}
}
}

+ 42
- 0
test/src/strset.t.c Parādīt failu

@@ -0,0 +1,42 @@
#include "strset.h"

#include <stdio.h>
#include <snow/snow.h>

describe(l2_strset) {
struct l2_strset set;

before_each() {
l2_strset_init(&set);
}

after_each() {
l2_strset_free(&set);
}

test("basic functionality") {
asserteq(l2_strset_put_copy(&set, "hello"), 1);
asserteq(l2_strset_put_copy(&set, "world"), 2);
asserteq(l2_strset_get(&set, "hello"), 1);
asserteq(l2_strset_get(&set, "world"), 2);
}

it("handles duplicates") {
asserteq(l2_strset_put_copy(&set, "hello"), 1);
asserteq(l2_strset_put_copy(&set, "hello"), 1);
asserteq(l2_strset_put_copy(&set, "world"), 2);
}

it("handles a whole bunch of values") {
char buf[128];
for (int i = 0; i < 1000; ++i) {
sprintf(buf, "test-%d", i);
asserteq(l2_strset_put_copy(&set, buf), i + 1);
}

for (int i = 0; i < 1000; ++i) {
sprintf(buf, "test-%d", i);
asserteq(l2_strset_get(&set, buf), i + 1);
}
}
}

Notiek ielāde…
Atcelt
Saglabāt