Skip to content

Commit

Permalink
[Add] quotes around metadata string in C, [Extend] compiled instr tes…
Browse files Browse the repository at this point in the history
…t to include metadata
  • Loading branch information
g5t committed Nov 17, 2023
1 parent e686fb6 commit f65f7ad
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
2 changes: 1 addition & 1 deletion mccode_antlr/translators/c_decls.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def one_line(name, typename, value, unit):
def metadata_table():
def one_line(defined_by, name, mimetype, value):
from ..common.utilities import escape_str_for_c
return f' "{defined_by}", "{name}", "{mimetype}", {escape_str_for_c(value)}, '
return f' "{defined_by}", "{name}", "{mimetype}", "{escape_str_for_c(value)}", '

metadata = source.collect_metadata()
lines = ['struct metadata_table_struct metadata_table[] = {']
Expand Down
8 changes: 3 additions & 5 deletions test/test_instr.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,16 +413,11 @@ def setUp(self):

class CompiledInstr(CompiledTest):
def test_one_axis(self):
from mccode_antlr.instr import Instr
from mccode_antlr.common import ComponentParameter, Expr
from mccode_antlr.compiler.c import compile_instrument, run_compiled_instrument, CBinaryTarget
from mccode_antlr.translators.target import MCSTAS_GENERATOR
from mccode_antlr.loader import read_mccode_dat
from tempfile import TemporaryDirectory
from os import R_OK, access
from pathlib import Path
from random import randint
from numpy import allclose

from math import pi, asin, sqrt
from mccode_antlr.loader import parse_mcstas_instr
Expand All @@ -443,6 +438,9 @@ def test_one_axis(self):
COMPONENT aperture = Slit(xwidth=virtual_source_x, yheight=virtual_source_y) AT (0, 0, 0.01) RELATIVE PREVIOUS
COMPONENT split_at = Arm() AT (0, 0, 0.0001) RELATIVE PREVIOUS
COMPONENT mono_point = Arm() AT (0, 0, 0.8) RELATIVE split_at
METADATA "txt" "something" %{{
This is some unparsed metadata that will be included as a literal string in the instrument.
%}}
COMPONENT mono = Monochromator_curved(zwidth = 0.02, yheight = 0.02, NH = 13, NV = 7, DM={d_spacing})
AT (0, 0, 0) RELATIVE mono_point ROTATED (0, a1, 0) RELATIVE mono_point
COMPONENT sample_arm = Arm() AT (0, 0, 0) RELATIVE mono_point ROTATED (0, a2, 0) RELATIVE mono_point
Expand Down

0 comments on commit f65f7ad

Please sign in to comment.