Skip to content

Commit 3f128b9

Browse files
committed
TIVarFile: use valid default name ("A") for scalar vars.
1 parent 269bb75 commit 3f128b9

3 files changed

Lines changed: 16 additions & 0 deletions

File tree

scripts/cli_smoke_tests.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ cmp -s "$TMP_DIR/one_real_raw.bin" "$TMP_DIR/one_real_roundtrip.bin"
1414

1515
printf '1' > "$TMP_DIR/one_real.txt"
1616
"$CLI" -i "$TMP_DIR/one_real.txt" -j readable -o "$TMP_DIR/one_real_83.83n" -k varfile -t Real -m 83 -n A
17+
"$CLI" -i "$TMP_DIR/one_real.txt" -j readable -o "$TMP_DIR/one_real_default.8xn" -k varfile -t Real

src/TIVarFile.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,11 @@ namespace tivars
172172
std::string default_var_name_for_type(const TIVarType& type)
173173
{
174174
const auto& typeName = type.getName();
175+
const auto typeId = type.getId();
176+
if (typeName == "Real" || typeName == "Complex" || (typeId >= 0x1B && typeId <= 0x21))
177+
{
178+
return "A";
179+
}
175180
if (typeName == "RealList" || typeName == "ComplexList")
176181
{
177182
return make_indexed_var_name(0x5D, 0x00);

tests.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2008,6 +2008,16 @@ End)";
20082008
}
20092009

20102010
{
2011+
TIVarFile realDefaultVar = TIVarFile::createNew("Real");
2012+
const uint8_t expectedScalarDefault[8] = {'A'};
2013+
assert(std::equal(realDefaultVar.getVarEntries()[0].varname, realDefaultVar.getVarEntries()[0].varname + 8, expectedScalarDefault));
2014+
2015+
TIVarFile complexDefaultVar = TIVarFile::createNew("Complex");
2016+
assert(std::equal(complexDefaultVar.getVarEntries()[0].varname, complexDefaultVar.getVarEntries()[0].varname + 8, expectedScalarDefault));
2017+
2018+
TIVarFile exactDefaultVar = TIVarFile::createNew("ExactRealPi", "", "83PCE");
2019+
assert(std::equal(exactDefaultVar.getVarEntries()[0].varname, exactDefaultVar.getVarEntries()[0].varname + 8, expectedScalarDefault));
2020+
20112021
TIVarFile listDefaultVar = TIVarFile::createNew("RealList");
20122022
const auto& listDefault = listDefaultVar.getVarEntries()[0];
20132023
const uint8_t expectedListDefault[8] = {0x5D, 0x00};

0 commit comments

Comments
 (0)