%!test %! ## TreatAsEmpty %! C = textscan ("1,2,3,NN,5,6\n", "%d%d%d%f", "delimiter", ",", "TreatAsEmpty", "NN"); %! assert (C{3}, int32 (3)); %! assert (C{4}, NaN); ## MultipleDelimsAsOne %!test %! str = "11, 12, 13,, 15\n21,, 23, 24, 25\n,, 33, 34, 35"; %! C = textscan (str, "%f %f %f %f", "delimiter", ",", "multipledelimsasone", 1, "endofline", "\n"); %! assert (C{1}', [11, 21, NaN]); %! assert (C{2}', [12, 23, 33]); %! assert (C{3}', [13, 24, 34]); %! assert (C{4}', [15, 25, 35]); ## Bug #44750 %!test %! assert (textscan ("/home/foo/", "%s", "delimiter", "/", "MultipleDelimsAsOne", 1){1}, ... %! {"home"; "foo"}); ## Allow cuddling %sliteral but warn it is ambiguous %!test %! C = textscan ("abcxyz51\nxyz83\n##xyz101", "%s xyz %d"); %! assert (C{1}([1 3]), {"abc"; "##"}); %! assert (isempty (C{1}{2}), true); %! assert (C{2}, int32([51; 83; 101])); ## Illegal format specifiers %!test %!error textscan ("1.0", "%z"); ## Test for false positives in check for non-supported format specifiers %!test %! assert (textscan ("Total: 32.5 % (of cm values)", "Total: %f % (of cm values)"){1}, 32.5, 1e-5); ## Test various forms of string format specifiers (bug #45712) %!test %! str = "14 :1 z:2 z:3 z:5 z:11"; %! C = textscan (str, "%f %s %*s %3s %*3s %f", "delimiter", ":"); %! assert ({a, b, c, d}, {14, {"1 z"}, {"3 z"}, 11}); %% Bit width, fixed width conv. specifiers %!test %! str2 = "123456789012345 "; %! str2 = [str2 str2 str2 str2 str2 str2 str2 str2]; %! str2 = [str2 "123456789.01234 1234567890.1234 12345.678901234 12345.678901234"]; %! pttrn = "%3u8%*s %5u16%*s %10u32%*s %15u64 %3d8%*s %5d16%*s %10d32%*s %15d64 %9f32%*s %14f64%*s %10.2f32%*s %12.2f64%*s"; %! C = textscan (str2, pttrn, "delimiter", " "); %! assert (C{1}, uint8 (123)); %! assert (C{2}, uint16 (12345)); %! assert (C{3}, uint32 (1234567890)); %! assert (C{4}, uint64 (123456789012345)); %! assert (C{5}, int8 (123)); %! assert (C{6}, int16 (12345)); %! assert (C{7}, int32 (1234567890)); %! assert (C{8}, int64 (123456789012345)); %! assert (C{9}, single (123456789), 1e-12); %! assert (C{10}, double (1234567890.123), 1e-15); %! assert (C{11}, single (12345.68), 1e-5); %! assert (C{12}, double (12345.68), 1e-11);