File: StringMethods.java

package info (click to toggle)
checker-framework-java 3.2.0%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 23,104 kB
  • sloc: java: 145,916; xml: 839; sh: 518; makefile: 404; perl: 26
file content (44 lines) | stat: -rw-r--r-- 1,105 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Tests for index annotations on string methods in the annotated JDK

class StringMethods {

    void testCharAt(String s, int i) {
        // ::  error: (argument.type.incompatible)
        s.charAt(i);
        // ::  error: (argument.type.incompatible)
        s.codePointAt(i);

        if (i >= 0 && i < s.length()) {
            s.charAt(i);
            s.codePointAt(i);
        }
    }

    void testCodePointBefore(String s) {
        // ::  error: (argument.type.incompatible)
        s.codePointBefore(0);

        if (s.length() > 0) {
            s.codePointBefore(s.length());
        }
    }

    void testSubstring(String s) {
        s.substring(0);
        s.substring(0, 0);
        s.substring(s.length());
        s.substring(s.length(), s.length());
        s.substring(0, s.length());
        // ::  error: (argument.type.incompatible)
        s.substring(1);
        // ::  error: (argument.type.incompatible)
        s.substring(0, 1);
    }

    void testIndexOf(String s, char c) {
        int i = s.indexOf(c);
        if (i != -1) {
            s.charAt(i);
        }
    }
}