Serene Runtime 1.0.0
C runtime for the Serene programming language
Loading...
Searching...
No Matches
ns_tests.h
Go to the documentation of this file.
1/* -*- C -*-
2 * Serene programming language
3 * Copyright (C) 2019-2026 Sameer Rahmani <[email protected]>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
19#pragma once
20
21#include "base.h"
22#include "serene/rt/core.h"
24#include "serene/rt/protocols.h"
25#include "serene/rt/strings.h"
26#include "serene/rt/symbols.h"
27
28#define NS_TESTS(X) X("namespace::make", test_ns_make)
29
30static void test_ns_make() {
31 MAKE_ENGINE(mm, engine);
32 MAKE_CONTEXT(engine, ctx);
33
34 srn_value_t *name = srn_string_make(ctx, &absurd_metadata, "serene.tests");
36
38 // ns should has it's own context
39 TEST_CHECK(AS_NS(ns)->root_context != ctx);
40 TEST_CHECK(AS_NS(ns)->sym_table.len == 0);
41
42 TEST_CHECK(srn_string_eq(AS_NS(ns)->name, AS_STRING(name)));
43
44 RELEASE_CONTEXT(ctx);
45 SHUTDOWN_ENGINE(mm, engine);
46}
#define TEST_CHECK(cond)
Definition acutest.h:96
#define RELEASE_CONTEXT(x)
Definition base.h:46
#define SHUTDOWN_ENGINE(mm, engine)
Definition base.h:38
#define MAKE_ENGINE(mm, engine)
Definition base.h:32
#define MAKE_CONTEXT(engine, x)
Definition base.h:42
static srn_metadata_t absurd_metadata
We use this for testing.
Definition core.h:66
@ VNamespace
Definition core.h:122
#define AS_STRING(value_ref)
Definition core.h:171
#define AS_NS(value_ref)
Definition core.h:170
#define IS_A(value_ref, field)
Definition core.h:162
srn_value_t * srn_namespace_make(srn_context_t *ctx, srn_metadata_t *metadata, srn_string_t *name)
Creates a new namespace in the give context.
Definition namespaces.c:27
static void test_ns_make()
Definition ns_tests.h:30
srn_value_t * srn_string_make(srn_context_t *ctx, srn_metadata_t *metadata, const char *src)
Create a string from a null terminated C string.
Definition strings.c:50
bool srn_string_eq(const srn_string_t *a, const srn_string_t *b)
Definition strings.c:76