• source navigation  • diff markup  • identifier search  • freetext search  • 

Sources/ucode/tests/custom/03_stdlib/59_rindex

  1 The `rindex()` function locates an element within a given array or a substring
  2 position within a given string, depending on the type of arguments given.
  3 
  4 Returns `null` if the given haystack argument is neither an array nor a string,
  5 returns `-1` if the element was not found within the array or the substring was
  6 not found within the string.
  7 
  8 Returns the last found index position in all other cases.
  9 
 10 -- Testcase --
 11 {%
 12         let o = {};
 13 
 14         printf("%.J\n", [
 15                 rindex([ 1, 2, "abc", 3, "abc", 1, 2 ], "abc"), // should return 4
 16                 rindex([ 1, 2, 3 ], 4),                                                 // should return -1
 17                 rindex([ [], {} ], {}),                                                 // should return -1 (strict equality)
 18                 rindex([ [], o ], o),                                                   // should return 1 (strict equality)
 19 
 20                 rindex("foobarfoobarfoobar", "arf"),                    // should return 10
 21                 rindex("test", "hello"),                                                // should return -1
 22                 rindex("test", "test"),                                                 // should return 0 (needle = haystack length special case)
 23                 rindex("test", ""),                                                             // should return 4 (zero length needle special case)
 24                 rindex("", ""),                                                                 // should return 0 (zero length special case)
 25                 rindex("foo\0foo\0foo", "o\0f"),                                // should return 6 (binary safe)
 26 
 27                 rindex({ test: true }, true),                                   // should return null
 28                 rindex(1234, 3),                                                                // should return null
 29         ]);
 30 %}
 31 -- End --
 32 
 33 -- Expect stdout --
 34 [
 35         4,
 36         -1,
 37         -1,
 38         1,
 39         10,
 40         -1,
 41         0,
 42         4,
 43         0,
 44         6,
 45         null,
 46         null
 47 ]
 48 -- End --

This page was automatically generated by LXR 0.3.1.  •  OpenWrt