Files
sdk/pkg/api_summary/test/node_test.dart
T
kevmoo a2055fbb82 pkg:api_summary
- Moved existing summary logic to the new package

Change-Id: I47d032f5a253cfa32d9b685d9ff18bb08f534177
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/499440
Commit-Queue: Vijay Menon <vsm@google.com>
Auto-Submit: Kevin Moore <kevmoo@google.com>
Reviewed-by: Vijay Menon <vsm@google.com>
2026-05-01 11:29:56 -07:00

98 lines
1.9 KiB
Dart

// Copyright (c) 2026, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// ignore_for_file: non_constant_identifier_names
import 'package:api_summary/src/node.dart';
import 'package:test/test.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
void main() {
defineReflectiveSuite(() {
defineReflectiveTests(NodeTest);
});
}
@reflectiveTest
class NodeTest {
void test_printNodes_indentChildNodes() {
var buf = StringBuffer();
printNodes(buf, [
(
1,
_SimpleNode('one', [
(2, _SimpleNode('two')),
(3, _SimpleNode('three')),
]),
),
(
4,
_SimpleNode('four', [
(5, _SimpleNode('five')),
(6, _SimpleNode('six')),
]),
),
]);
expect(buf.toString(), '''
one
two
three
four
five
six
''');
}
void test_printNodes_joinTextStrings() {
var buf = StringBuffer();
printNodes(buf, [
(1, Node<num>()..text.addAll(['x', 0])),
]);
expect(buf.toString(), '''
x0
''');
}
void test_printNodes_sortChildNodesByKey() {
var buf = StringBuffer();
printNodes(buf, [
(
0,
_SimpleNode('zero', [
(2, _SimpleNode('two')),
(1, _SimpleNode('one')),
(3, _SimpleNode('three')),
]),
),
]);
expect(buf.toString(), '''
zero
one
two
three
''');
}
void test_printNodes_sortedByKey() {
var buf = StringBuffer();
printNodes(buf, [
(2, _SimpleNode('two')),
(1, _SimpleNode('one')),
(3, _SimpleNode('three')),
]);
expect(buf.toString(), '''
one
two
three
''');
}
}
class _SimpleNode extends Node<num> {
_SimpleNode(String text, [List<(num, Node<num>)> childNodes = const []]) {
this.text.add(text);
this.childNodes.addAll(childNodes);
}
}