Serene Runtime 1.0.0
C runtime for the Serene programming language
Loading...
Searching...
No Matches
context_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/strings.h"
25
26#define CTX_TESTS(X) \
27 X("context::make", test_context_make), \
28 X("context::ns_registeration", test_namespace_registeration)
29
30static void test_context_make() {
31 MAKE_ENGINE(mm, engine);
32 MAKE_CONTEXT(engine, ctx);
33 ASSERT_NOT_NULL(ctx);
34 ASSERT_NOT_NULL(ctx->engine);
35 TEST_CHECK(ctx->parent == nullptr);
36 RELEASE_CONTEXT(ctx);
37 SHUTDOWN_ENGINE(mm, engine);
38}
39
41 MAKE_ENGINE(mm, engine);
42 MAKE_CONTEXT(engine, ctx);
43
44 srn_value_t *name = srn_string_make(ctx, &absurd_metadata, "serene.tests");
46
48 srn_error_t *err = srn_context_register_namespace(ctx, AS_NS(ns));
49
50 TEST_CHECK(err == nullptr);
51
52 TEST_CHECK(ctx->engine->namespaces.len == 1);
53
54 RELEASE_CONTEXT(ctx);
55 SHUTDOWN_ENGINE(mm, engine);
56}
#define TEST_CHECK(cond)
Definition acutest.h:96
#define RELEASE_CONTEXT(x)
Definition base.h:46
#define ASSERT_NOT_NULL(x)
Definition base.h:30
#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 void test_context_make()
static void test_namespace_registeration()
static srn_metadata_t absurd_metadata
We use this for testing.
Definition core.h:66
#define TYPE(value_ref)
Definition core.h:160
@ VNamespace
Definition core.h:122
#define AS_STRING(value_ref)
Definition core.h:171
#define AS_NS(value_ref)
Definition core.h:170
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
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