Skip to content

Commit ef4a0d9

Browse files
committed
format source code
1 parent fc79767 commit ef4a0d9

24 files changed

+284
-189
lines changed

hxformat.json

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
{
2+
"emptyLines": {
3+
"afterFileHeaderComment": 0,
4+
"abstractEmptyLines": {
5+
"afterPrivateFunctions": 2,
6+
"afterPrivateVars": 2,
7+
"afterStaticFunctions": 2,
8+
"afterStaticVars": 2,
9+
"afterVars": 2,
10+
"beginType": 1,
11+
"betweenFunctions": 2,
12+
"betweenStaticFunctions": 2,
13+
"existingBetweenFields": "remove"
14+
},
15+
"classEmptyLines": {
16+
"afterPrivateFunctions": 2,
17+
"afterPrivateVars": 2,
18+
"afterStaticFunctions": 2,
19+
"afterStaticVars": 2,
20+
"afterVars": 2,
21+
"beginType": 1,
22+
"betweenFunctions": 2,
23+
"betweenStaticFunctions": 2,
24+
"existingBetweenFields": "remove"
25+
},
26+
"enumAbstractEmptyLines": {
27+
"afterVars": 2,
28+
"beginType": 1,
29+
"betweenFunctions": 2,
30+
"betweenVars": 2,
31+
"existingBetweenFields": "remove"
32+
},
33+
"interfaceEmptyLines": {
34+
"afterPrivateFunctions": 2,
35+
"afterPrivateVars": 2,
36+
"afterStaticFunctions": 2,
37+
"afterStaticVars": 2,
38+
"afterVars": 2,
39+
"beginType": 1,
40+
"betweenFunctions": 2,
41+
"betweenStaticFunctions": 2,
42+
"existingBetweenFields": "remove"
43+
},
44+
"beforeDocCommentEmptyLines": "ignore",
45+
"afterLeftCurly": "keep",
46+
"betweenTypes": 2,
47+
"maxAnywhereInFile": 2
48+
},
49+
"indentation": {
50+
"character": " ",
51+
"conditionalPolicy": "alignedIncrease",
52+
"tabWidth": 3
53+
},
54+
"lineEnds": {
55+
"emptyCurly": "break"
56+
},
57+
"sameLine": {
58+
"caseBody": "keep",
59+
"ifBody": "keep"
60+
},
61+
"wrapping": {
62+
"maxLineLength": 140,
63+
"callParameter": {
64+
"rules": [
65+
{
66+
"conditions": [
67+
{
68+
"cond": "ItemCountLargerThan",
69+
"value": 2
70+
}
71+
],
72+
"type": "keep"
73+
}
74+
]
75+
},
76+
"methodChain": {
77+
"rules": [
78+
{
79+
"conditions": [
80+
{
81+
"cond": "ItemCountLargerThan",
82+
"value": 1
83+
}
84+
],
85+
"type": "keep"
86+
}
87+
]
88+
}
89+
}
90+
}

src/hx/doctest/DocTestGenerator.hx

+3-3
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,10 @@ class DocTestGenerator {
292292
continue;
293293

294294
// generate a new testMethod if required
295-
if (testMethodAssertions.length == MAX_ASSERTIONS_PER_TEST_METHOD
295+
if (testMethodAssertions.length == MAX_ASSERTIONS_PER_TEST_METHOD //
296296
// for haxe-unit and munit we create a new test-method per assertion:
297-
|| Types.isInstanceOf(doctestAdapter, HaxeUnitDocTestAdapter)
298-
|| Types.isInstanceOf(doctestAdapter, MUnitDocTestAdapter)
297+
|| Types.isInstanceOf(doctestAdapter, HaxeUnitDocTestAdapter)
298+
|| Types.isInstanceOf(doctestAdapter, MUnitDocTestAdapter) //
299299
) {
300300
testMethodsCount++;
301301
final testMethodName = 'test${src.haxeModuleName}_$testMethodsCount';

src/hx/doctest/DocTestRunner.hx

+17-20
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ package hx.doctest;
77

88
import haxe.PosInfos;
99
import haxe.Timer;
10-
1110
import hx.doctest.internal.DocTestUtils;
1211
import hx.doctest.internal.Logger;
1312

@@ -21,6 +20,8 @@ class DocTestRunner {
2120
travix.Logger.exit(exitCode);
2221
#else
2322
#if sys
23+
Sys.stderr().flush();
24+
Sys.stdout().flush();
2425
Sys.exit(exitCode);
2526
#elseif js
2627
final isPhantomJSDirectExecution = js.Syntax.code("(typeof phantom !== 'undefined')");
@@ -67,7 +68,10 @@ class DocTestRunner {
6768
* look for functions starting with "test" and invoke them
6869
*/
6970
Logger.log(DEBUG, 'Looking for test cases in [${thisClassName}]...');
70-
final funcNames = [ for (funcName in Type.getInstanceFields(thisClass)) if (funcName.startsWith("test")) funcName ];
71+
final funcNames = [
72+
for (funcName in Type.getInstanceFields(thisClass))
73+
if (funcName.startsWith("test")) funcName
74+
];
7175
funcNames.sort((a, b) -> a < b ? -1 : a > b ? 1 : 0);
7276
for (funcName in funcNames) {
7377
final func:Null<Dynamic> = Reflect.field(this, funcName);
@@ -113,7 +117,6 @@ class DocTestRunner {
113117
return testsFailed;
114118
}
115119

116-
117120
/**
118121
* Runs the accumulated doc tests and exits the process with exit code 0 in case all
119122
* tests were passed or 1 in case test failures occured.
@@ -123,15 +126,13 @@ class DocTestRunner {
123126
exit(exitCode);
124127
}
125128

126-
127129
/**
128130
* for use within manually created test method
129131
*/
130132
@:nullSafety(Off) // TODO https://github.com/HaxeFoundation/haxe/issues/10272
131133
function assertEquals(leftResult:Null<Dynamic>, rightResult:Null<Dynamic>, ?pos:PosInfos):Void
132134
results.add(DocTestUtils.deepEquals(leftResult, rightResult), 'assertEquals($leftResult, $rightResult)', pos);
133135

134-
135136
/**
136137
* for use within manually created test method
137138
*/
@@ -140,7 +141,6 @@ class DocTestRunner {
140141
results.add(!result, 'assertFalse($result)', pos);
141142
}
142143

143-
144144
/**
145145
* for use within manually created test method
146146
*/
@@ -150,7 +150,6 @@ class DocTestRunner {
150150
results.add(result >= min && result <= max, 'assertInRange($result, $min, $max)', pos);
151151
}
152152

153-
154153
/**
155154
* for use within manually created test method
156155
*/
@@ -159,7 +158,6 @@ class DocTestRunner {
159158
results.add(result <= max, 'assertMax($result, $max)', pos);
160159
}
161160

162-
163161
/**
164162
* for use within manually created test method
165163
*/
@@ -168,31 +166,27 @@ class DocTestRunner {
168166
results.add(result >= min, 'assertMin($result, $min)', pos);
169167
}
170168

171-
172169
/**
173170
* for use within manually created test method
174171
*/
175172
@:nullSafety(Off) // TODO https://github.com/HaxeFoundation/haxe/issues/10272
176173
function assertNotSame(leftResult:Null<Dynamic>, rightResult:Null<Dynamic>, ?pos:PosInfos):Void
177174
results.add(leftResult != rightResult, 'assertNotSame($leftResult, $rightResult)', pos);
178175

179-
180176
/**
181177
* for use within manually created test method
182178
*/
183179
@:nullSafety(Off) // TODO https://github.com/HaxeFoundation/haxe/issues/10272
184180
function assertNotEquals(leftResult:Null<Dynamic>, rightResult:Null<Dynamic>, ?pos:PosInfos):Void
185181
results.add(!DocTestUtils.deepEquals(leftResult, rightResult), 'assertNotEquals($leftResult, $rightResult)', pos);
186182

187-
188183
/**
189184
* for use within manually created test method
190185
*/
191186
@:nullSafety(Off) // TODO https://github.com/HaxeFoundation/haxe/issues/10272
192187
function assertSame(leftResult:Null<Dynamic>, rightResult:Null<Dynamic>, ?pos:PosInfos):Void
193188
results.add(leftResult == rightResult, 'assertSame($leftResult, $rightResult)', pos);
194189

195-
196190
/**
197191
* for use within manually created test method
198192
*/
@@ -201,7 +195,6 @@ class DocTestRunner {
201195
results.add(result, 'assertTrue($result)', pos);
202196
}
203197

204-
205198
/**
206199
* for use within manually created test method
207200
*/
@@ -210,7 +203,6 @@ class DocTestRunner {
210203
results.add(false, msg, pos);
211204
}
212205

213-
214206
@:allow(hx.doctest.DocTestResults)
215207
function onDocTestResult(result:DocTestResult) {
216208
final pos:PosInfosExt = {
@@ -233,8 +225,10 @@ interface DocTestResults {
233225
var testsPassed(default, null):Int;
234226
var testsFailed(default, null):Int;
235227

228+
236229
function add(success:Bool, msg:String, pos:haxe.PosInfos):Void;
237230

231+
238232
/**
239233
* @deprecated use `DocTestResults#testsFailed`
240234
*/
@@ -256,6 +250,7 @@ interface DocTestResults {
256250

257251

258252
class DocTestResult {
253+
259254
public final date = Date.now();
260255
public final testPassed:Bool;
261256
public final msg:String;
@@ -270,10 +265,9 @@ class DocTestResult {
270265

271266

272267
public function toString():String {
273-
return
274-
'${pos.fileName}:${pos.lineNumber}: ' +
275-
(pos.charStart == null ? "" : 'characters ${pos.charStart}-${pos.charEnd}: ') +
276-
'[${testPassed ? "OK" : "ERROR"}] $msg';
268+
return '${pos.fileName}:${pos.lineNumber}: '
269+
+ (pos.charStart == null ? "" : 'characters ${pos.charStart}-${pos.charEnd}: ')
270+
+ '[${testPassed ? "OK" : "ERROR"}] $msg';
277271
}
278272
}
279273

@@ -284,6 +278,7 @@ class DefaultDocTestResults implements DocTestResults {
284278
public var testsFailed(default, null) = 0;
285279
public var tests(default, null):Array<DocTestResult> = [];
286280

281+
287282
final runner:DocTestRunner;
288283

289284

@@ -303,11 +298,13 @@ class DefaultDocTestResults implements DocTestResults {
303298

304299

305300
@:deprecated
306-
public function getFailureCount():Int return testsFailed;
301+
public function getFailureCount():Int
302+
return testsFailed;
307303

308304

309305
@:deprecated
310-
public function getSuccessCount():Int return testsFailed;
306+
public function getSuccessCount():Int
307+
return testsFailed;
311308

312309

313310
public function logFailures():Void

src/hx/doctest/internal/DocTestAssertion.hx

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class DocTestAssertion {
1111
public final expression:String;
1212
public final pos:PosInfosExt;
1313

14+
1415
public function new(file:SourceFile, expression:String, lineNumber:Int, charStart:Int, charEnd:Int) {
1516
this.expression = expression;
1617
pos = {
@@ -23,6 +24,7 @@ class DocTestAssertion {
2324
};
2425
}
2526

27+
2628
public function toString():String {
2729
return 'DocTestAssertion[pos="${pos.fileName}:${pos.lineNumber}", expr={ $expression }]';
2830
}

0 commit comments

Comments
 (0)