From 63d820bd6864e35423bbba56537228ce1f19c245 Mon Sep 17 00:00:00 2001 From: Guido Cella Date: Thu, 9 May 2024 22:58:19 +0200 Subject: [PATCH] test: test mp_guess_lang_from_filename() --- test/language.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/language.c b/test/language.c index 78599469bf..1ee7de65b3 100644 --- a/test/language.c +++ b/test/language.c @@ -54,4 +54,27 @@ int main(void) assert_int_equal(mp_match_lang(LANGS("ax") , NULL) , 0); assert_int_equal(mp_match_lang(LANGS("") , "ax") , 0); assert_int_equal(mp_match_lang((char*[]){NULL} , "ax") , 0); + + void *ta_ctx = talloc_new(NULL); + int start; // this is actually the position of the delimiter. + + assert_string_equal(bstrto0(ta_ctx, mp_guess_lang_from_filename(bstr0("foo.en.srt"), &start)), "en"); + assert_int_equal(start, 3); + assert_string_equal(bstrto0(ta_ctx, mp_guess_lang_from_filename(bstr0("foo.eng.srt"), NULL)), "eng"); + assert_string_equal(bstrto0(ta_ctx, mp_guess_lang_from_filename(bstr0("foo.e.srt"), NULL)), ""); + assert_string_equal(bstrto0(ta_ctx, mp_guess_lang_from_filename(bstr0("foo.engg.srt"), NULL)), ""); + assert_string_equal(bstrto0(ta_ctx, mp_guess_lang_from_filename(bstr0("foo.00.srt"), NULL)), ""); + assert_string_equal(bstrto0(ta_ctx, mp_guess_lang_from_filename(bstr0("foo.srt"), NULL)), ""); + assert_string_equal(bstrto0(ta_ctx, mp_guess_lang_from_filename(bstr0(NULL), NULL)), ""); + + assert_string_equal(bstrto0(ta_ctx, mp_guess_lang_from_filename(bstr0("foo.en-US.srt"), NULL)), "en-US"); + assert_string_equal(bstrto0(ta_ctx, mp_guess_lang_from_filename(bstr0("foo.en-simple.srt"), NULL)), "en-simple"); + assert_string_equal(bstrto0(ta_ctx, mp_guess_lang_from_filename(bstr0("foo.sgn-FSL.srt"), NULL)), "sgn-FSL"); + assert_string_equal(bstrto0(ta_ctx, mp_guess_lang_from_filename(bstr0("foo.gsw-u-sd-chzh.srt"), NULL)), "gsw-u-sd-chzh"); + assert_string_equal(bstrto0(ta_ctx, mp_guess_lang_from_filename(bstr0("foo.en-.srt"), NULL)), ""); + assert_string_equal(bstrto0(ta_ctx, mp_guess_lang_from_filename(bstr0("foo.en-US-.srt"), NULL)), ""); + assert_string_equal(bstrto0(ta_ctx, mp_guess_lang_from_filename(bstr0("foo.en-aaaaaaaaa.srt"), NULL)), ""); + assert_string_equal(bstrto0(ta_ctx, mp_guess_lang_from_filename(bstr0("foo.en-0.srt"), NULL)), ""); + + talloc_free(ta_ctx); }