liuyn
2024-03-11 a87f1c3df03078814ee97ad0c8ac200a232419e9
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
45
46
47
48
49
50
51
52
53
54
@isTest
private class CSVReaderTest {
    public static testMethod void readIETFRFC4180CSVValueTest() {
        String data = null;  // Placeholder for data to use in testing.
        
        System.debug(data = Parser.CRLF);
        new CSVReader.CSVValue('', false, Parser.CRLF)
                .assertEquals(CSVReader.readIETFRFC4180CSVValue(data));
        
        System.debug(data = '""' + Parser.CRLF);
        new CSVReader.CSVValue('', true, Parser.CRLF)
                .assertEquals(CSVReader.readIETFRFC4180CSVValue(data));
        
        System.debug(data = '"",asdf' + Parser.CRLF);
        new CSVReader.CSVValue('', true, Parser.COMMA)
                .assertEquals(CSVReader.readIETFRFC4180CSVValue(data));
        
        System.debug(data = ',asdf' + Parser.CRLF);
        new CSVReader.CSVValue('', false, Parser.COMMA)
                .assertEquals(CSVReader.readIETFRFC4180CSVValue(data));
        
        System.debug(data = '"' + Parser.CRLF + '",blah' + Parser.CRLF);
        new CSVReader.CSVValue(Parser.CRLF, true, Parser.COMMA)
                .assertEquals(CSVReader.readIETFRFC4180CSVValue(data));
        
        System.debug(data = '"""marty""","""chang"""' + Parser.CRLF);
        new CSVReader.CSVValue('"marty"', true, Parser.COMMA)
                .assertEquals(CSVReader.readIETFRFC4180CSVValue(data));
        
        System.debug(data = '"com""pli""cate' + Parser.CRLF + 'd"'
                + Parser.CRLF);
        new CSVReader.CSVValue('com"pli"cate' + Parser.CRLF + 'd', true, Parser.CRLF)
                .assertEquals(CSVReader.readIETFRFC4180CSVValue(data));
        
        System.debug(data = 'asdf' + Parser.CRLF);
        new CSVReader.CSVValue('asdf', false, Parser.CRLF)
                .assertEquals(CSVReader.readIETFRFC4180CSVValue(data));
    }
 
    /**
     * Tests one case of parsing a CSV file that contains the following data:
     *
     * abc,"def","g""h""i"
     * "j
     * kl","m
     * n""o""",
     */
    public static testMethod void readIETFRFC4180CSVFile() {
      String data = 'abc,"def","g""h""i"' + Parser.CRLF + '"j' + Parser.CRLF
             + 'kl","m' + Parser.CRLF + 'n""o""",';
      List<List<String>> fileValues =
             CSVReader.readIETFRFC4180CSVFile(Blob.valueOf(data));
    }
}