Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(46)

Side by Side Diff: test/codegen/expect/lib/convert/line_splitter_test.js

Issue 2128353002: Check in codegen test expectations. (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 dart_library.library('lib/convert/line_splitter_test', null, /* Imports */[
2 'dart_sdk',
3 'expect'
4 ], function load__line_splitter_test(exports, dart_sdk, expect) {
5 'use strict';
6 const core = dart_sdk.core;
7 const convert = dart_sdk.convert;
8 const math = dart_sdk.math;
9 const _interceptors = dart_sdk._interceptors;
10 const async = dart_sdk.async;
11 const dart = dart_sdk.dart;
12 const dartx = dart_sdk.dartx;
13 const expect$ = expect.expect;
14 const line_splitter_test = Object.create(null);
15 let JSArrayOfString = () => (JSArrayOfString = dart.constFn(_interceptors.JSAr ray$(core.String)))();
16 let SinkOfString = () => (SinkOfString = dart.constFn(core.Sink$(core.String)) )();
17 let VoidTovoid = () => (VoidTovoid = dart.constFn(dart.definiteFunctionType(da rt.void, [])))();
18 let dynamicAndStringTodynamic = () => (dynamicAndStringTodynamic = dart.constF n(dart.definiteFunctionType(dart.dynamic, [dart.dynamic, core.String])))();
19 let StringToString = () => (StringToString = dart.constFn(dart.definiteFunctio nType(core.String, [core.String])))();
20 let dynamicTovoid = () => (dynamicTovoid = dart.constFn(dart.definiteFunctionT ype(dart.void, [dart.dynamic])))();
21 let StringTovoid = () => (StringTovoid = dart.constFn(dart.definiteFunctionTyp e(dart.void, [core.String])))();
22 line_splitter_test.lineTerminators = dart.constList(['\n', '\r', '\r\n'], core .String);
23 line_splitter_test.main = function() {
24 line_splitter_test.testSimpleConvert();
25 line_splitter_test.testSplit();
26 line_splitter_test.testSplitWithOffsets();
27 line_splitter_test.testManyLines();
28 line_splitter_test.testReadLine1();
29 line_splitter_test.testReadLine2();
30 line_splitter_test.testChunkedConversion();
31 };
32 dart.fn(line_splitter_test.main, VoidTovoid());
33 let const$;
34 line_splitter_test.testManyLines = function() {
35 let breakIndex = 0;
36 let inputs = const$ || (const$ = dart.constList(['line1', 'line2', 'long lin e 3', ' line 4 ', 'l5'], core.String));
37 let buffer = inputs[dartx.fold](dart.dynamic)(new core.StringBuffer(), dart. fn((buff, e) => {
38 dart.dsend(buff, 'write', e);
39 dart.dsend(buff, 'write', line_splitter_test.lineTerminators[dartx.get](br eakIndex));
40 breakIndex++;
41 breakIndex = breakIndex[dartx['%']](line_splitter_test.lineTerminators[dar tx.length]);
42 return buff;
43 }, dynamicAndStringTodynamic()));
44 let foo = line_splitter_test._getLinesSliced(dart.toString(buffer));
45 expect$.Expect.equals(inputs[dartx.join](), foo);
46 };
47 dart.fn(line_splitter_test.testManyLines, VoidTovoid());
48 line_splitter_test._getLinesSliced = function(str) {
49 let lines = null;
50 let stringSink = convert.StringConversionSink.withCallback(dart.fn(result => lines = result, StringToString()));
51 let sink = new convert.LineSplitter().startChunkedConversion(stringSink);
52 let chunkSize = 3;
53 let index = 0;
54 while (index < dart.notNull(str[dartx.length])) {
55 let end = math.min(core.int)(str[dartx.length], index + chunkSize);
56 sink.addSlice(str, index, end, false);
57 index = index + chunkSize;
58 }
59 sink.close();
60 return lines;
61 };
62 dart.fn(line_splitter_test._getLinesSliced, StringToString());
63 line_splitter_test.testSimpleConvert = function() {
64 let decoder = new convert.LineSplitter();
65 for (let lf of line_splitter_test.lineTerminators) {
66 let test = dart.str`line1${lf}line2${lf}line3`;
67 let result = decoder.convert(test);
68 expect$.Expect.listEquals(JSArrayOfString().of(['line1', 'line2', 'line3'] ), result);
69 }
70 let test = "Line1\nLine2\r\nLine3\rLine4\n\n\n\r\n\r\n\r\r";
71 let result = decoder.convert(test);
72 expect$.Expect.listEquals(JSArrayOfString().of(['Line1', 'Line2', 'Line3', ' Line4', '', '', '', '', '', '']), result);
73 };
74 dart.fn(line_splitter_test.testSimpleConvert, VoidTovoid());
75 let const$0;
76 line_splitter_test.testReadLine1 = function() {
77 let controller = async.StreamController.new({sync: true});
78 let stream = controller.stream.transform(core.String)(convert.UTF8.decoder). transform(core.String)(const$0 || (const$0 = dart.const(new convert.LineSplitter ())));
79 let stage = 0;
80 let done = false;
81 function stringData(line) {
82 expect$.Expect.equals(stage, 0);
83 expect$.Expect.equals("Line", line);
84 stage++;
85 }
86 dart.fn(stringData, dynamicTovoid());
87 function streamClosed() {
88 expect$.Expect.equals(1, stage);
89 done = true;
90 }
91 dart.fn(streamClosed, VoidTovoid());
92 stream.listen(stringData, {onDone: streamClosed});
93 controller.add("Line"[dartx.codeUnits]);
94 controller.close();
95 expect$.Expect.isTrue(done, 'should be done by now');
96 };
97 dart.fn(line_splitter_test.testReadLine1, VoidTovoid());
98 let const$1;
99 line_splitter_test.testReadLine2 = function() {
100 let controller = async.StreamController.new({sync: true});
101 let stream = controller.stream.transform(core.String)(convert.UTF8.decoder). transform(core.String)(const$1 || (const$1 = dart.const(new convert.LineSplitter ())));
102 let expectedLines = JSArrayOfString().of(['Line1', 'Line2', 'Line3', 'Line4' , '', '', '', '', '', '', 'Line5', 'Line6']);
103 let index = 0;
104 stream.listen(dart.fn(line => {
105 expect$.Expect.equals(expectedLines[dartx.get](index++), line);
106 }, StringTovoid()));
107 controller.add("Line1\nLine2\r\nLine3\rLi"[dartx.codeUnits]);
108 controller.add("ne4\n"[dartx.codeUnits]);
109 controller.add("\n\n\r\n\r\n\r\r"[dartx.codeUnits]);
110 controller.add("Line5\r"[dartx.codeUnits]);
111 controller.add("\nLine6\n"[dartx.codeUnits]);
112 controller.close();
113 expect$.Expect.equals(expectedLines[dartx.length], index);
114 };
115 dart.fn(line_splitter_test.testReadLine2, VoidTovoid());
116 line_splitter_test.testSplit = function() {
117 for (let lf of line_splitter_test.lineTerminators) {
118 let test = dart.str`line1${lf}line2${lf}line3`;
119 let result = convert.LineSplitter.split(test)[dartx.toList]();
120 expect$.Expect.listEquals(JSArrayOfString().of(['line1', 'line2', 'line3'] ), result);
121 }
122 let test = "Line1\nLine2\r\nLine3\rLine4\n\n\n\r\n\r\n\r\r";
123 let result = convert.LineSplitter.split(test)[dartx.toList]();
124 expect$.Expect.listEquals(JSArrayOfString().of(['Line1', 'Line2', 'Line3', ' Line4', '', '', '', '', '', '']), result);
125 };
126 dart.fn(line_splitter_test.testSplit, VoidTovoid());
127 line_splitter_test.testSplitWithOffsets = function() {
128 for (let lf of line_splitter_test.lineTerminators) {
129 let test = dart.str`line1${lf}line2${lf}line3`;
130 let i2 = 5 + dart.notNull(lf[dartx.length]);
131 expect$.Expect.equals(5 + dart.notNull(lf[dartx.length]), i2);
132 let result = convert.LineSplitter.split(test, 4)[dartx.toList]();
133 expect$.Expect.listEquals(JSArrayOfString().of(['1', 'line2', 'line3']), r esult);
134 result = convert.LineSplitter.split(test, 5)[dartx.toList]();
135 expect$.Expect.listEquals(JSArrayOfString().of(['', 'line2', 'line3']), re sult);
136 result = convert.LineSplitter.split(test, i2)[dartx.toList]();
137 expect$.Expect.listEquals(JSArrayOfString().of(['line2', 'line3']), result );
138 result = convert.LineSplitter.split(test, 0, i2 + 2)[dartx.toList]();
139 expect$.Expect.listEquals(JSArrayOfString().of(['line1', 'li']), result);
140 result = convert.LineSplitter.split(test, i2, i2 + 5)[dartx.toList]();
141 expect$.Expect.listEquals(JSArrayOfString().of(['line2']), result);
142 }
143 let test = "Line1\nLine2\r\nLine3\rLine4\n\n\n\r\n\r\n\r\r";
144 let result = convert.LineSplitter.split(test)[dartx.toList]();
145 expect$.Expect.listEquals(JSArrayOfString().of(['Line1', 'Line2', 'Line3', ' Line4', '', '', '', '', '', '']), result);
146 test = "a\n\nb\r\nc\n\rd\r\re\r\n\nf\r\n";
147 result = convert.LineSplitter.split(test)[dartx.toList]();
148 expect$.Expect.listEquals(JSArrayOfString().of(["a", "", "b", "c", "", "d", "", "e", "", "f"]), result);
149 };
150 dart.fn(line_splitter_test.testSplitWithOffsets, VoidTovoid());
151 line_splitter_test.testChunkedConversion = function() {
152 let test = "a\n\nb\r\nc\n\rd\r\re\r\n\nf\rg\nh\r\n";
153 let result = JSArrayOfString().of(["a", "", "b", "c", "", "d", "", "e", "", "f", "g", "h"]);
154 for (let i = 0; i < dart.notNull(test[dartx.length]); i++) {
155 let output = [];
156 let splitter = new convert.LineSplitter();
157 let outSink = convert.ChunkedConversionSink.withCallback(dart.bind(output, dartx.addAll));
158 let sink = splitter.startChunkedConversion(SinkOfString()._check(outSink)) ;
159 sink.addSlice(test, 0, i, false);
160 sink.addSlice(test, i, test[dartx.length], false);
161 sink.close();
162 expect$.Expect.listEquals(result, output);
163 }
164 for (let i = 0; i < dart.notNull(test[dartx.length]); i++) {
165 for (let j = i; j < dart.notNull(test[dartx.length]); j++) {
166 let output = [];
167 let splitter = new convert.LineSplitter();
168 let outSink = convert.ChunkedConversionSink.withCallback(dart.bind(outpu t, dartx.addAll));
169 let sink = splitter.startChunkedConversion(SinkOfString()._check(outSink ));
170 sink.addSlice(test, 0, i, false);
171 sink.addSlice(test, i, j, false);
172 sink.addSlice(test, j, test[dartx.length], true);
173 expect$.Expect.listEquals(result, output);
174 }
175 }
176 };
177 dart.fn(line_splitter_test.testChunkedConversion, VoidTovoid());
178 // Exports:
179 exports.line_splitter_test = line_splitter_test;
180 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698