10#include "testing/testing.h"
14using namespace blender::bke::path_templates;
21 type =
"UNESCAPED_CURLY_BRACE";
24 type =
"VARIABLE_SYNTAX";
27 type =
"FORMAT_SPECIFIER";
30 type =
"UNKNOWN_VARIABLE";
35 fmt::format_to(std::back_inserter(s),
48 fmt::format_to(std::back_inserter(s),
"[");
50 for (
const Error &error : errors) {
55 fmt::format_to(std::back_inserter(s),
", ");
59 fmt::format_to(std::back_inserter(s),
"]");
234 variables.
add_string(
"sanitize",
"./\\?*:|\"<>");
235 variables.
add_string(
"long",
"This string is exactly 32 bytes_");
240 variables.
add_float(
"pi", 3.14159265358979323846);
241 variables.
add_float(
"e", 2.71828182845904523536);
242 variables.
add_float(
"ntsc", 30.0 / 1.001);
244 variables.
add_float(
"f_negative", -3.14159265358979323846);
245 variables.
add_float(
"huge", 200000000000000000000000000000000.0);
246 variables.
add_float(
"tiny", 0.000000000000000000000000000000002);
252 "{hi}_{bye}_{empty}_{sanitize}_{path}"
253 "_{the_answer}_{prime}_{i_negative}_{pi}_{e}_{ntsc}_{two}"
254 "_{f_negative}_{huge}_{tiny}",
255 "hello_goodbye__.__________C:\\and/or/../nor/"
256 "_42_7_-7_3.141592653589793_2.718281828459045_29.970029970029973_2.0"
257 "_-3.141592653589793_2e+32_2e-33",
263 "{the_answer:#}_{the_answer:##}_{the_answer:####}_{i_negative:####}",
270 "{the_answer:.###}_{the_answer:#.##}_{the_answer:###.##}_{i_negative:###.####}",
271 "42.000_42.00_042.00_-07.0000",
277 "{pi:.####}_{e:.###}_{ntsc:.########}_{two:.##}_{f_negative:.##}_{huge:.##}_{tiny:.##}",
278 "3.1416_2.718_29.97002997_2.00_-3.14_200000000000000010732324408786944.00_0.00",
284 "{pi:##.####}_{e:####.###}_{ntsc:#.########}_{two:###.##}_{f_negative:###.##}_{huge:###."
286 "03.1416_0002.718_29.97002997_002.00_-03.14_200000000000000010732324408786944.00_000.00",
292 "{pi:##}_{e:####}_{ntsc:#}_{two:###}",
299 "{hi}_{{hi}}_{{{bye}}}_{bye}",
300 "hello_{hi}_{goodbye}_goodbye",
317 "{pi:##.}_{e:####.}_{ntsc:#.}_{two:###.}_{f_negative:###.}_{huge:###.}_{tiny:###.}",
318 "{pi:##.}_{e:####.}_{ntsc:#.}_{two:###.}_{f_negative:###.}_{huge:###.}_{tiny:###.}",
332 "{hi}_{missing}_{bye}",
333 "{hi}_{missing}_{bye}",
359 "{prime:}_{prime:.}_{prime:#.#.#}_{prime:sup}_{prime::sup}_{prime}",
360 "{prime:}_{prime:.}_{prime:#.#.#}_{prime:sup}_{prime::sup}_{prime}",
397 "___{long}{long}{long}{long}{long}{long}{long}{long}{long}{long}{long}{long}{long}{long}"
398 "{long}{long}{long}{long}{long}{long}{long}{long}{long}{long}{long}{long}{long}{long}{"
399 "long}{long}{long}{long}{long}{long}{long}{long}{long}{long}{long}{long}{long}{long}{"
400 "long}{long}{long}{long}{long}{long}{long}{long}{long}{long}{long}{long}{long}{long}{"
401 "long}{long}{long}{long}{long}{long}{long}{long}{long}{long}{long}{long}{long}{long}{"
402 "long}{long}{long}{long}{long}{long}{long}{long}{long}{long}{long}{long}{long}{long}{"
403 "long}{long}{long}{long}{long}{long}{long}{long}{long}{long}{long}{long}{long}{long}{"
404 "long}{long}{long}{long}{long}{long}{long}{long}{long}{long}{long}{long}{long}{long}{"
405 "long}{long}{long}{long}{long}{long}{long}{long}{long}{long}{long}{long}{long}{long}{"
406 "long}{long}{long}{long}{long}{long}{long}{long}{long}{long}{long}{long}{long}{long}{"
407 "long}{long}{long}{long}{long}{long}{long}{long}{long}{long}{long}{long}{long}{long}{"
408 "long}{long}{long}{long}{long}{long}{long}{long}{long}{long}{long}{long}{long}{long}{"
411 "___This string is exactly 32 bytes_This string is exactly 32 bytes_This string is "
412 "exactly 32 bytes_This string is exactly 32 bytes_This string is exactly 32 bytes_This "
413 "string is exactly 32 bytes_This string is exactly 32 bytes_This string is exactly 32 "
414 "bytes_This string is exactly 32 bytes_This string is exactly 32 bytes_This string is "
415 "exactly 32 bytes_This string is exactly 32 bytes_This string is exactly 32 bytes_This "
416 "string is exactly 32 bytes_This string is exactly 32 bytes_This string is exactly 32 "
417 "bytes_This string is exactly 32 bytes_This string is exactly 32 bytes_This string is "
418 "exactly 32 bytes_This string is exactly 32 bytes_This string is exactly 32 bytes_This "
419 "string is exactly 32 bytes_This string is exactly 32 bytes_This string is exactly 32 "
420 "bytes_This string is exactly 32 bytes_This string is exactly 32 bytes_This string is "
421 "exactly 32 bytes_This string is exactly 32 bytes_This string is exactly 32 bytes_This "
422 "string is exactly 32 bytes_This string is exactly 32 bytes_This string is exactly 32 "
431 STRNCPY(path, test_case.path_in);
435 EXPECT_EQ(validation_errors, test_case.expected_errors)
437 <<
" Expected errors: " <<
errors_to_string(test_case.expected_errors) << std::endl
438 <<
" Note: test_case.path_in = " << test_case.path_in << std::endl;
439 EXPECT_STREQ(path, test_case.path_in)
440 <<
" Note: test_case.path_in = " << test_case.path_in << std::endl;
444 EXPECT_EQ(application_errors, test_case.expected_errors)
445 <<
" Template errors: " <<
errors_to_string(application_errors) << std::endl
446 <<
" Expected errors: " <<
errors_to_string(test_case.expected_errors) << std::endl
447 <<
" Note: test_case.path_in = " << test_case.path_in << std::endl;
448 EXPECT_STREQ(path, test_case.path_result)
449 <<
" Note: test_case.path_in = " << test_case.path_in << std::endl;
460 "/studio/{{pröj}}/日本語.ocio");
467 variables.
add_string(
"long",
"This string is exactly 32 bytes_");
473 const int max_output_alloc_size = 40;
476 "{long}{short}{empty}{number}",
477 "This string is exactly 32 bytes_hi42",
482 "fooThis string is exactly 32 bytes_bar",
501 "foo{number:####}bar",
518 "No template expressions here.",
519 "No template expressions here.",
525 "foo{long}{long}{long}{long}bar",
526 "fooThis string is exactly 32 bytes_This",
532 "foo{non_existant_variable}bar",
533 "foo{non_existant_variable}bar",
547 "foo{long}{long}{long}{long}{long}{long}{long}{bar",
548 "foo{long}{long}{long}{long}{long}{long}{long}{bar",
554 const int in_size = strlen(test_case.path_in) + 1;
559 &buffer, max_output_alloc_size, variables);
560 EXPECT_EQ(application_errors, test_case.expected_errors)
561 <<
" Template errors: " <<
errors_to_string(application_errors) << std::endl
562 <<
" Expected errors: " <<
errors_to_string(test_case.expected_errors) << std::endl
563 <<
" Note: test_case.path_in = " << test_case.path_in << std::endl;
564 EXPECT_STREQ(buffer, test_case.path_result)
565 <<
" Note: test_case.path_in = " << test_case.path_in << std::endl
566 <<
" Note: test_case.path_result = " << test_case.path_result << std::endl;
Functions and classes for evaluating template expressions in filepaths.
constexpr int64_t size() const
constexpr IndexRange()=default
constexpr int64_t start() const
std::optional< int64_t > get_integer(StringRef name) const
bool add_filename_only(StringRef var_name, StringRefNull full_path, StringRef fallback)
bool add_float(StringRef name, double value)
bool add_path_up_to_file(StringRef var_name, StringRefNull full_path, StringRef fallback)
bool remove(StringRef name)
std::optional< double > get_float(StringRef name) const
std::optional< StringRefNull > get_filepath(StringRef name) const
std::optional< StringRefNull > get_string(StringRef name) const
bool add_integer(StringRef name, int64_t value)
bool contains(StringRef name) const
bool add_string(StringRef name, StringRef value)
bool add_filepath(StringRef name, StringRef value)
#define EXPECT_FALSE(result)
#define EXPECT_TRUE(result)
static std::string error_to_string(const Error &error)
static std::string errors_to_string(Span< Error > errors)
TEST_F(AnimDataTest, BKE_fcurves_id_cb_test)
char * STRNCPY(char(&dst)[N], const char *src)
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
Vector< bke::path_templates::Error > BKE_path_apply_template_alloc(char **path, int path_maxncpy, const bke::path_templates::VariableMap &template_variables)
Vector< bke::path_templates::Error > BKE_path_apply_template(char *path, int path_maxncpy, const bke::path_templates::VariableMap &template_variables)
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
std::string BKE_path_template_escape(StringRef text)
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
Vector< bke::path_templates::Error > BKE_path_validate_template(StringRef path, const bke::path_templates::VariableMap &template_variables)
char path_result[FILE_MAX]
Vector< Error > expected_errors