Added tests and silence a warning
This commit is contained in:
parent
0898030e4c
commit
eff5bd0362
2 changed files with 19 additions and 2 deletions
|
|
@ -122,7 +122,7 @@ inline absl::optional<ValueType> readOpcode(absl::string_view value, const Range
|
|||
if (!absl::SimpleAtoi(value, &returnedValue)) {
|
||||
float floatValue;
|
||||
if (!absl::SimpleAtof(value, &floatValue))
|
||||
return {};
|
||||
return absl::nullopt;
|
||||
returnedValue = static_cast<int64_t>(floatValue);
|
||||
}
|
||||
|
||||
|
|
@ -151,7 +151,7 @@ inline absl::optional<ValueType> readOpcode(absl::string_view value, const Range
|
|||
value = value.substr(0, numberEnd);
|
||||
|
||||
float returnedValue;
|
||||
if (!absl::SimpleAtof(value.substr(0, numberEnd), &returnedValue))
|
||||
if (!absl::SimpleAtof(value, &returnedValue))
|
||||
return absl::nullopt;
|
||||
|
||||
return validRange.clamp(returnedValue);
|
||||
|
|
|
|||
|
|
@ -246,3 +246,20 @@ TEST_CASE("[Opcode] Normalization")
|
|||
|
||||
REQUIRE(sfz::Opcode("SaMpLe", "").cleanUp(sfz::kOpcodeScopeRegion).opcode == "sample");
|
||||
}
|
||||
|
||||
TEST_CASE("[Opcode] readOpcode")
|
||||
{
|
||||
REQUIRE( sfz::readOpcode("16", sfz::Range<uint8_t>(0, 100)).value() == 16 );
|
||||
REQUIRE( sfz::readOpcode("110", sfz::Range<uint8_t>(0, 100)).value() == 100 );
|
||||
REQUIRE( sfz::readOpcode("-1", sfz::Range<uint8_t>(0, 100)).value() == 0 );
|
||||
REQUIRE( sfz::readOpcode("12.5", sfz::Range<int>(-100, 100)).value() == 12 );
|
||||
REQUIRE( sfz::readOpcode("-40", sfz::Range<int>(-100, 100)).value() == -40 );
|
||||
REQUIRE( sfz::readOpcode("-140", sfz::Range<int>(-100, 100)).value() == -100 );
|
||||
REQUIRE( sfz::readOpcode("12.5", sfz::Range<float>(0.0f, 100.0f)).value() == 12.5_a );
|
||||
REQUIRE( sfz::readOpcode("-22.5", sfz::Range<float>(-20.0f, 100.0f)).value() == -20.0_a );
|
||||
REQUIRE( sfz::readOpcode("150.5", sfz::Range<float>(-20.0f, 100.0f)).value() == 100.0_a );
|
||||
REQUIRE( sfz::readOpcode("50.25garbage", sfz::Range<float>(-20.0f, 100.0f)).value() == 50.25_a );
|
||||
REQUIRE( sfz::readOpcode("50.25garbage", sfz::Range<int>(-20, 100)).value() == 50 );
|
||||
REQUIRE( !sfz::readOpcode("garbage50.25", sfz::Range<int>(-20, 100)) );
|
||||
REQUIRE( !sfz::readOpcode("garbage", sfz::Range<int>(-20, 100)) );
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue