summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJohnny Richard <johnny@johnnyrichard.com>2023-04-26 00:40:44 +0200
committerCarlos Maniero <carlosmaniero@gmail.com>2023-04-25 23:19:13 -0300
commit127dae1c3b48c3a4dceddb9000309bfeaa8d0a01 (patch)
tree4d92b3a7b4c29f0ace3a5ff699e4789f60b0aa46 /test
parentc1a1bd2320b4c1508c4ab20d23b7c193a94d8026 (diff)
style: Use clang-format as formatter and linter tool
We want to keep the code style consistent, this first commit adds a .clang-format in order to "document" our style code. This patch also adds a target *linter* to Makefile which will complain if we have any style issue on test and src dirs. I have run the follow command to create the .clang-format file: $ clang-format -style=mozilla -dump-config > .clang-format And I also made some adjusts to .clang-format changing the following properties: PointerAlignment: Right ColumnLimit: 120 Commands executed to fix the current styling: $ find . -name *.h | xargs clang-format -i $ find . -name *.c | xargs clang-format -i Signed-off-by: Johnny Richard <johnny@johnnyrichard.com>
Diffstat (limited to 'test')
-rw-r--r--test/Makefile4
-rw-r--r--test/integration_test.c50
-rw-r--r--test/lexer_test.c70
-rw-r--r--test/munit.c3
-rw-r--r--test/munit.h1
-rw-r--r--test/parser_test.c89
-rw-r--r--test/string_view_test.c64
-rw-r--r--test/vector_test.c72
8 files changed, 167 insertions, 186 deletions
diff --git a/test/Makefile b/test/Makefile
index 40f5cf9..717b430 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -14,6 +14,10 @@ all: munit.o $(TESTS)
clean:
$(RM) *.o *_test
+.PHONY: linter
+linter: $(SRCS)
+ clang-format --dry-run --Werror $?
+
string_view_test: munit.o ../build/string_view.o string_view_test.o
$(CC) $? $(CFLAGS) -o $@
diff --git a/test/integration_test.c b/test/integration_test.c
index b6c0f36..739a938 100644
--- a/test/integration_test.c
+++ b/test/integration_test.c
@@ -1,26 +1,26 @@
/*
-* Copyright (C) 2023 Carlos Maniero
-*
-* This program is free software: you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation, either version 3 of the License, or
-* (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program. If not, see <https://www.gnu.org/licenses/>.
-*/
+ * Copyright (C) 2023 Carlos Maniero
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
#define MUNIT_ENABLE_ASSERT_ALIASES
+#include "munit.h"
#include <stdio.h>
#include <string.h>
-#include "munit.h"
void
-assert_exit_status(char* filename, int expected_exit_status)
+assert_exit_status(char *filename, int expected_exit_status)
{
char command[255] = "../pipa --silent --out /tmp/pipa_program ";
strcat(command, filename);
@@ -32,15 +32,13 @@ assert_exit_status(char* filename, int expected_exit_status)
if (WIFEXITED(status)) {
int exit_status = WEXITSTATUS(status);
assert_int(expected_exit_status, ==, exit_status);
- }
- else {
+ } else {
assert_string_equal("", "Exited with error");
}
}
static MunitResult
-test_examples(const MunitParameter params[],
- void *user_data_or_fixture)
+test_examples(const MunitParameter params[], void *user_data_or_fixture)
{
assert_exit_status("../examples/main.pipa", 69);
assert_exit_status("../examples/arithmetics.pipa", 13);
@@ -48,14 +46,10 @@ test_examples(const MunitParameter params[],
return MUNIT_OK;
}
-static MunitTest tests[] = {
- { "/test_examples", test_examples, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL },
- { NULL, NULL, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL }
-};
+static MunitTest tests[] = { { "/test_examples", test_examples, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL },
+ { NULL, NULL, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL } };
-static const MunitSuite suite = {
- "/integration_tests", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE
-};
+static const MunitSuite suite = { "/integration_tests", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE };
int
main(int argc, char *argv[])
diff --git a/test/lexer_test.c b/test/lexer_test.c
index 0eebfe5..abfac16 100644
--- a/test/lexer_test.c
+++ b/test/lexer_test.c
@@ -1,32 +1,32 @@
/*
-* Copyright (C) 2023 Carlos Maniero
-*
-* This program is free software: you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation, either version 3 of the License, or
-* (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program. If not, see <https://www.gnu.org/licenses/>.
-*/
+ * Copyright (C) 2023 Carlos Maniero
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
#define MUNIT_ENABLE_ASSERT_ALIASES
-#include "munit.h"
#include "lexer.h"
+#include "munit.h"
void
make_lexer_from_static_src(lexer_t *lexer, char *src, int srclen)
{
- lexer->srclen = 0;
- lexer->cur = 0;
- lexer->row = 0;
- lexer->bol = 0;
- lexer->src = src;
- lexer->srclen = srclen;
+ lexer->srclen = 0;
+ lexer->cur = 0;
+ lexer->row = 0;
+ lexer->bol = 0;
+ lexer->src = src;
+ lexer->srclen = srclen;
}
void
@@ -51,27 +51,24 @@ assert_token_at(char *source, int token_index, token_kind_t expected_kind, char
assert_string_equal(expected, actual);
}
-
static MunitResult
-test_tokenize_number(const MunitParameter params[],
- void *user_data_or_fixture)
+test_tokenize_number(const MunitParameter params[], void *user_data_or_fixture)
{
- assert_token_at("1", 0, TOKEN_NUMBER, "1");
- assert_token_at(" 13 ", 0, TOKEN_NUMBER, "13");
+ assert_token_at("1", 0, TOKEN_NUMBER, "1");
+ assert_token_at(" 13 ", 0, TOKEN_NUMBER, "13");
assert_token_at(" \n 13 ", 0, TOKEN_NUMBER, "13");
return MUNIT_OK;
}
static MunitResult
-test_tokenize_op(const MunitParameter params[],
- void *user_data_or_fixture)
+test_tokenize_op(const MunitParameter params[], void *user_data_or_fixture)
{
- assert_token_at(" + 2", 0, TOKEN_OP, "+");
+ assert_token_at(" + 2", 0, TOKEN_OP, "+");
assert_token_at(" - \n", 0, TOKEN_OP, "-");
- assert_token_at(" * ;", 0, TOKEN_OP, "*");
- assert_token_at(" / ", 0, TOKEN_OP, "/");
- assert_token_at(" = ", 0, TOKEN_OP, "=");
+ assert_token_at(" * ;", 0, TOKEN_OP, "*");
+ assert_token_at(" / ", 0, TOKEN_OP, "/");
+ assert_token_at(" = ", 0, TOKEN_OP, "=");
assert_token_at("1 * 2", 0, TOKEN_NUMBER, "1");
assert_token_at("1 * 2", 1, TOKEN_OP, "*");
@@ -81,8 +78,7 @@ test_tokenize_op(const MunitParameter params[],
}
static MunitResult
-test_tokenize_unknown(const MunitParameter params[],
- void *user_data_or_fixture)
+test_tokenize_unknown(const MunitParameter params[], void *user_data_or_fixture)
{
assert_token_at(" @ ", 0, TOKEN_UNKNOWN, "@");
assert_token_at(" $ ", 0, TOKEN_UNKNOWN, "$");
@@ -97,9 +93,7 @@ static MunitTest tests[] = {
{ NULL, NULL, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL }
};
-static const MunitSuite suite = {
- "/lexer_test", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE
-};
+static const MunitSuite suite = { "/lexer_test", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE };
int
main(int argc, char *argv[])
diff --git a/test/munit.c b/test/munit.c
index 00ede07..2500018 100644
--- a/test/munit.c
+++ b/test/munit.c
@@ -1,3 +1,4 @@
+// clang-format off
/* Copyright (c) 2013-2018 Evan Nemerson <evan@nemerson.com>
*
* Permission is hereby granted, free of charge, to any person
@@ -496,8 +497,8 @@ struct PsnipClockTimespec {
(defined(PSNIP_CLOCK_CPU_METHOD) && (PSNIP_CLOCK_CPU_METHOD == PSNIP_CLOCK_METHOD_GETRUSAGE)) || \
(defined(PSNIP_CLOCK_WALL_METHOD) && (PSNIP_CLOCK_WALL_METHOD == PSNIP_CLOCK_METHOD_GETRUSAGE)) || \
(defined(PSNIP_CLOCK_MONOTONIC_METHOD) && (PSNIP_CLOCK_MONOTONIC_METHOD == PSNIP_CLOCK_METHOD_GETRUSAGE))
-# include <sys/time.h>
# include <sys/resource.h>
+# include <sys/time.h>
#endif
#if \
diff --git a/test/munit.h b/test/munit.h
index 8460a45..c614c78 100644
--- a/test/munit.h
+++ b/test/munit.h
@@ -1,3 +1,4 @@
+// clang-format off
/* µnit Testing Framework
* Copyright (c) 2013-2017 Evan Nemerson <evan@nemerson.com>
*
diff --git a/test/parser_test.c b/test/parser_test.c
index daa2fe7..d8aee07 100644
--- a/test/parser_test.c
+++ b/test/parser_test.c
@@ -1,19 +1,19 @@
/*
-* Copyright (C) 2023 Carlos Maniero
-*
-* This program is free software: you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation, either version 3 of the License, or
-* (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program. If not, see <https://www.gnu.org/licenses/>.
-*/
+ * Copyright (C) 2023 Carlos Maniero
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
#define MUNIT_ENABLE_ASSERT_ALIASES
#include "ast.h"
#include "lexer.h"
@@ -22,22 +22,24 @@
#include "string.h"
#include "vector.h"
-void assert_string_view_equal(char *expected, string_view_t actual);
+void
+assert_string_view_equal(char *expected, string_view_t actual);
void
make_lexer_from_static_src(lexer_t *lexer, char *src)
{
lexer->filepath = "test.pipa";
- lexer->srclen = 0;
- lexer->cur = 0;
- lexer->row = 0;
- lexer->bol = 0;
- lexer->src = src;
- lexer->srclen = strlen(src);
+ lexer->srclen = 0;
+ lexer->cur = 0;
+ lexer->row = 0;
+ lexer->bol = 0;
+ lexer->src = src;
+ lexer->srclen = strlen(src);
}
void
-assert_parser_error(char* src, char* error_msg) {
+assert_parser_error(char *src, char *error_msg)
+{
parser_t parser;
lexer_t lexer;
@@ -55,8 +57,7 @@ assert_parser_error(char* src, char* error_msg) {
}
static MunitResult
-test_parse_function(const MunitParameter params[],
- void *user_data_or_fixture)
+test_parse_function(const MunitParameter params[], void *user_data_or_fixture)
{
parser_t parser;
lexer_t lexer;
@@ -89,8 +90,7 @@ test_parse_function(const MunitParameter params[],
}
static MunitResult
-test_parse_variable_definition(const MunitParameter params[],
- void *user_data_or_fixture)
+test_parse_variable_definition(const MunitParameter params[], void *user_data_or_fixture)
{
parser_t parser;
lexer_t lexer;
@@ -129,8 +129,7 @@ test_parse_variable_definition(const MunitParameter params[],
}
static MunitResult
-test_parse_arithmetic_expression(const MunitParameter params[],
- void *user_data_or_fixture)
+test_parse_arithmetic_expression(const MunitParameter params[], void *user_data_or_fixture)
{
parser_t parser;
lexer_t lexer;
@@ -189,7 +188,8 @@ test_parse_arithmetic_expression(const MunitParameter params[],
return MUNIT_OK;
}
-void assert_string_view_equal(char *expected, string_view_t actual)
+void
+assert_string_view_equal(char *expected, string_view_t actual)
{
size_t expected_len = strlen(expected);
assert_int(expected_len, ==, actual.size);
@@ -197,22 +197,21 @@ void assert_string_view_equal(char *expected, string_view_t actual)
}
static MunitResult
-test_parse_basic_syntax_errors(const MunitParameter params[],
- void *user_data_or_fixture)
+test_parse_basic_syntax_errors(const MunitParameter params[], void *user_data_or_fixture)
{
- assert_parser_error("(): i32 { return 42; }" , "expected 'TOKEN_NAME' but got '('");
- assert_parser_error("main): i32 { return 42; }" , "expected '(' but got ')'");
- assert_parser_error("main(: i32 { return 42; }" , "expected ')' but got ':'");
- assert_parser_error("main() i32 { return 42; }" , "expected ':' but got 'TOKEN_NAME'");
- assert_parser_error("main(): { return 42; }" , "expected 'TOKEN_NAME' but got '{'");
- assert_parser_error("main(): i32 return 42; }" , "expected '{' but got 'TOKEN_NAME'");
- assert_parser_error("main(): i32 { 42; }" , "expected 'TOKEN_NAME' but got 'TOKEN_NUMBER'");
- assert_parser_error("main(): i32 { return; }" , "unexpected '; (;)' token");
- assert_parser_error("main(): i32 { return 42;" , "expected '}' but got end of file");
- assert_parser_error("main(): beff { return 42; }" , "type 'beff' is not defined");
+ assert_parser_error("(): i32 { return 42; }", "expected 'TOKEN_NAME' but got '('");
+ assert_parser_error("main): i32 { return 42; }", "expected '(' but got ')'");
+ assert_parser_error("main(: i32 { return 42; }", "expected ')' but got ':'");
+ assert_parser_error("main() i32 { return 42; }", "expected ':' but got 'TOKEN_NAME'");
+ assert_parser_error("main(): { return 42; }", "expected 'TOKEN_NAME' but got '{'");
+ assert_parser_error("main(): i32 return 42; }", "expected '{' but got 'TOKEN_NAME'");
+ assert_parser_error("main(): i32 { 42; }", "expected 'TOKEN_NAME' but got 'TOKEN_NUMBER'");
+ assert_parser_error("main(): i32 { return; }", "unexpected '; (;)' token");
+ assert_parser_error("main(): i32 { return 42;", "expected '}' but got end of file");
+ assert_parser_error("main(): beff { return 42; }", "type 'beff' is not defined");
// FIXME: once function calls are implemented, this error should inform that
// neither a variable or function call was found.
- assert_parser_error("main(): i32 { oxi 42; }" , "expected ':' but got 'TOKEN_NUMBER'");
+ assert_parser_error("main(): i32 { oxi 42; }", "expected ':' but got 'TOKEN_NUMBER'");
return MUNIT_OK;
}
@@ -227,9 +226,7 @@ static MunitTest tests[] = {
{ NULL, NULL, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL }
};
-static const MunitSuite suite = {
- "/parser", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE
-};
+static const MunitSuite suite = { "/parser", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE };
int
main(int argc, char *argv[])
diff --git a/test/string_view_test.c b/test/string_view_test.c
index 130ec2c..d94f190 100644
--- a/test/string_view_test.c
+++ b/test/string_view_test.c
@@ -1,53 +1,50 @@
/*
-* Copyright (C) 2023 Johnny Richard
-*
-* This program is free software: you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation, either version 3 of the License, or
-* (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program. If not, see <https://www.gnu.org/licenses/>.
-*/
+ * Copyright (C) 2023 Johnny Richard
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
#define MUNIT_ENABLE_ASSERT_ALIASES
#include "munit.h"
#include "string_view.h"
static MunitResult
-test_create_new(const MunitParameter params[],
- void *user_data_or_fixture)
+test_create_new(const MunitParameter params[], void *user_data_or_fixture)
{
char *str = "hello world";
string_view_t sv = string_view_new(str, strlen(str));
- assert_string_equal("hello world", (char *) sv.str);
+ assert_string_equal("hello world", (char *)sv.str);
assert_int(sv.size, ==, strlen(str));
return MUNIT_OK;
}
static MunitResult
-test_from_str(const MunitParameter params[],
- void *user_data_or_fixture)
+test_from_str(const MunitParameter params[], void *user_data_or_fixture)
{
char *str = "hello world";
string_view_t sv = string_view_from_str(str);
- assert_string_equal(str, (char *) sv.str);
+ assert_string_equal(str, (char *)sv.str);
assert_int(sv.size, ==, strlen(str));
return MUNIT_OK;
}
static MunitResult
-test_to_str(const MunitParameter params[],
- void *user_data_or_fixture)
+test_to_str(const MunitParameter params[], void *user_data_or_fixture)
{
char *str = "hello world";
@@ -62,8 +59,7 @@ test_to_str(const MunitParameter params[],
}
static MunitResult
-test_eq(const MunitParameter params[],
- void *user_data_or_fixture)
+test_eq(const MunitParameter params[], void *user_data_or_fixture)
{
string_view_t a = string_view_from_str("hello");
string_view_t b = string_view_from_str("world");
@@ -77,17 +73,13 @@ test_eq(const MunitParameter params[],
return MUNIT_OK;
}
-static MunitTest tests[] = {
- { "/test_create_new", test_create_new, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL },
- { "/test_from_str", test_from_str, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL },
- { "/test_to_str", test_to_str, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL },
- { "/test_eq", test_eq, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL },
- { NULL, NULL, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL }
-};
-
-static const MunitSuite suite = {
- "/string_view", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE
-};
+static MunitTest tests[] = { { "/test_create_new", test_create_new, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL },
+ { "/test_from_str", test_from_str, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL },
+ { "/test_to_str", test_to_str, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL },
+ { "/test_eq", test_eq, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL },
+ { NULL, NULL, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL } };
+
+static const MunitSuite suite = { "/string_view", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE };
int
main(int argc, char *argv[])
diff --git a/test/vector_test.c b/test/vector_test.c
index e327735..11e2363 100644
--- a/test/vector_test.c
+++ b/test/vector_test.c
@@ -1,26 +1,25 @@
/*
-* Copyright (C) 2023 Johnny Richard
-*
-* This program is free software: you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation, either version 3 of the License, or
-* (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program. If not, see <https://www.gnu.org/licenses/>.
-*/
+ * Copyright (C) 2023 Johnny Richard
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
#define MUNIT_ENABLE_ASSERT_ALIASES
#include "munit.h"
#include "vector.h"
static MunitResult
-test_create_new(const MunitParameter params[],
- void *user_data_or_fixture)
+test_create_new(const MunitParameter params[], void *user_data_or_fixture)
{
vector_t *vec = vector_new();
@@ -47,20 +46,19 @@ test_create_new(const MunitParameter params[],
}
static MunitResult
-test_push_back(const MunitParameter params[],
- void *user_data_or_fixture)
+test_push_back(const MunitParameter params[], void *user_data_or_fixture)
{
vector_t *vec = vector_new();
int number1 = 1;
int number2 = 2;
- vector_push_back(vec, (void *) &number1);
- vector_push_back(vec, (void *) &number2);
+ vector_push_back(vec, (void *)&number1);
+ vector_push_back(vec, (void *)&number2);
assert_int(vec->size, ==, 2);
- assert_int(*((int *) vector_at(vec, 0)), ==, number1);
- assert_int(*((int *) vector_at(vec, 1)), ==, number2);
+ assert_int(*((int *)vector_at(vec, 0)), ==, number1);
+ assert_int(*((int *)vector_at(vec, 1)), ==, number2);
vector_destroy(vec);
@@ -68,8 +66,7 @@ test_push_back(const MunitParameter params[],
}
static MunitResult
-test_vector_push_back_until_resize(const MunitParameter params[],
- void *user_data_or_fixture)
+test_vector_push_back_until_resize(const MunitParameter params[], void *user_data_or_fixture)
{
vector_t *vec = vector_new();
@@ -77,17 +74,17 @@ test_vector_push_back_until_resize(const MunitParameter params[],
for (int i = 0; i < VECTOR_INITIAL_CAPACITY; ++i) {
items[i] = 1;
- vector_push_back(vec, (void *) &items[i]);
+ vector_push_back(vec, (void *)&items[i]);
}
items[VECTOR_INITIAL_CAPACITY] = 1;
- vector_push_back(vec, (void *) &items[VECTOR_INITIAL_CAPACITY]);
+ vector_push_back(vec, (void *)&items[VECTOR_INITIAL_CAPACITY]);
assert_int(vec->size, ==, VECTOR_INITIAL_CAPACITY + 1);
assert_int(vec->capacity, ==, VECTOR_INITIAL_CAPACITY * 2);
for (int i = 0; i < vec->size; ++i) {
- assert_int(*((int *) vec->items[i]), ==, 1);
+ assert_int(*((int *)vec->items[i]), ==, 1);
}
vector_destroy(vec);
@@ -95,17 +92,18 @@ test_vector_push_back_until_resize(const MunitParameter params[],
return MUNIT_OK;
}
-static MunitTest tests[] = {
- { "/test_create_new", test_create_new, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL },
- { "/test_push_back", test_push_back, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL },
- { "/test_vector_push_back_until_resize", test_vector_push_back_until_resize, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL },
+static MunitTest tests[] = { { "/test_create_new", test_create_new, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL },
+ { "/test_push_back", test_push_back, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL },
+ { "/test_vector_push_back_until_resize",
+ test_vector_push_back_until_resize,
+ NULL,
+ NULL,
+ MUNIT_TEST_OPTION_NONE,
+ NULL },
- { NULL, NULL, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL }
-};
+ { NULL, NULL, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL } };
-static const MunitSuite suite = {
- "/vector", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE
-};
+static const MunitSuite suite = { "/vector", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE };
int
main(int argc, char *argv[])