forked from akvelon/flutter-code-editor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode_read_only_test.dart
More file actions
158 lines (143 loc) · 3.8 KB
/
Copy pathcode_read_only_test.dart
File metadata and controls
158 lines (143 loc) · 3.8 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import 'package:flutter_code_editor/src/code/code.dart';
import 'package:flutter_code_editor/src/named_sections/parsers/brackets_start_end.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:highlight/languages/angelscript.dart';
import 'package:highlight/languages/java.dart';
import 'package:highlight/languages/javascript.dart';
import 'package:highlight/languages/typescript.dart';
final _language = java;
void main() {
group('Code. Read-only.', () {
test('Parse read-only lines by end comments', () {
const dataSets = [
{
'text': '''
readonly
editable// readonly
''', // Empty line inherits readonly
'readonly': [false, true, true],
},
{
'text': '''
readonly
readonly //readonly
readonly // a readonly b'''
'\n\n'
'''
The above line is empty but not last, so does not inherit readonly
''',
'readonly': [false, true, true, false, false, false],
},
{
'text': '''
readonly
editable// readonly
''', // Last after read only, but not empty, so editable.
'readonly': [false, true, false],
},
];
for (final data in dataSets) {
final code = Code(
text: data['text']! as String,
language: _language,
);
final readonly = data['readonly']! as List<bool>;
for (int i = code.lines.lines.length; --i >= 0;) {
expect(
code.lines.lines[i].isReadOnly,
readonly[i],
reason: 'Line #$i',
);
}
}
});
test(
'Does not parse an unsupported language',
() {
const textWithReadonly = 'end of line // readonly';
final code = Code(text: textWithReadonly, language: angelscript);
expect(code.lines.lines.first.isReadOnly, false);
},
);
test('Lines in read-only sections are read-only', () {
const text = '''
public class MyClass {
public void main() { // [START section1]
}
// [END section1]
// [START section2]
void method() {
}
// [END section2]
}
''';
const expected = [
false,
true,
true,
true,
false,
false,
false,
false,
false,
false,
];
final code = Code(
text: text,
namedSectionParser: const BracketsStartEndNamedSectionParser(),
readOnlySectionNames: {'section1', 'nonexistent'},
language: java,
);
expect(
code.lines.lines.map((line) => line.isReadOnly),
expected,
);
});
test('Lines in read-only sections are read-only for JS/TS Language', () {
const text = '''
export class MyTypeScriptClass {
run() { // [START section1]
}
// [END section1]
// [START section2]
method() {
}
// [END section2]
}
''';
const expected = [
false,
true,
true,
true,
false,
false,
false,
false,
false,
false,
];
final codeTypescript = Code(
text: text,
namedSectionParser: const BracketsStartEndNamedSectionParser(),
readOnlySectionNames: {'section1', 'nonexistent'},
language: typescript,
);
final codeJavascript = Code(
text: text,
namedSectionParser: const BracketsStartEndNamedSectionParser(),
readOnlySectionNames: {'section1', 'nonexistent'},
language: javascript,
);
expect(
codeTypescript.lines.lines.map((line) => line.isReadOnly),
expected,
);
expect(
codeJavascript.lines.lines.map((line) => line.isReadOnly),
expected,
);
});
});
}