Skip to content

Commit

Permalink
Merge pull request #65 from keertip/tests
Browse files Browse the repository at this point in the history
some more unit tests
  • Loading branch information
keertip committed Jan 9, 2015
2 parents 17ddc0d + 197a00a commit fe5cf41
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 44 deletions.
16 changes: 0 additions & 16 deletions lib/src/css.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,14 @@

library dartdoc.css;

import 'dart:convert';
import 'dart:io';

class CSS {

// The bootstrap css file
final String cssFilePath = '/packages/bootstrap/css/bootstrap.css';

final String cssHeader =
'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css';

final String theme =
'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap-theme.min.css';

final String jsScript =
'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js';

String getCssName() => 'bootstrap.css';

String getCssContent() {
var script = new File(Platform.script.toFilePath());
var cssFile = new File('${script.parent.path}$cssFilePath');
String text = cssFile.readAsStringSync(encoding: ASCII);
return text;
}

}
2 changes: 2 additions & 0 deletions lib/src/model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,8 @@ class ModelFunction extends ModelElement {

FunctionElement get _func => (element as FunctionElement);

bool get isStatic => _func.isStatic;

String get typeName => 'Functions';

String createLinkedSummary(Helper generator) {
Expand Down
2 changes: 2 additions & 0 deletions test/all.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ library dartdoc.all_tests;

import 'css_test.dart' as css_tests;
import 'dartdoc_test.dart' as dartdoc_tests;
import 'io_utils_test.dart' as io_utils_tests;
import 'model_test.dart' as model_tests;
import 'package_utils_test.dart' as package_util_tests;
import 'template_test.dart' as template_tests;
Expand All @@ -14,6 +15,7 @@ import 'template_test.dart' as template_tests;
main() {
css_tests.tests();
dartdoc_tests.tests();
io_utils_tests.tests();
model_tests.tests();
package_util_tests.tests();
template_tests.tests();
Expand Down
7 changes: 0 additions & 7 deletions test/css_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,5 @@ tests() {
});
});

test('js script exists', () {
var url = css.jsScript;
http.get(url).then((response) {
expect(response.statusCode, 200);
});
});

});
}
22 changes: 22 additions & 0 deletions test/io_utils_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (c) 2015, 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.

library dartdoc.io_utils_test;

import 'dart:io';

import 'package:unittest/unittest.dart';

import '../lib/src/io_utils.dart';

tests() {
group('io utils', () {

test('find files to document', () {
var files = findFilesToDocumentInPackage(Directory.current.path);
expect(files.length, 1);
});

});
}
90 changes: 69 additions & 21 deletions test/model_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ import 'package:analyzer/src/generated/sdk_io.dart';
import 'package:analyzer/src/generated/source_io.dart';

const SOURCE1 = r'''
library ex;
static int function1(String s, bool b) => 5;
get y => 2;
class A {
const int n = 5;
static String s = 'hello';
Expand All @@ -28,69 +34,111 @@ class A {
get m => 0;
}
class B extends A {
void m(){}
}
abstract class C {}
''';

main() {
tests();
}

tests() {

AnalyzerHelper helper = new AnalyzerHelper();

Source source = helper.addSource(SOURCE1);
LibraryElement e = helper.resolve(source);
var l = new Library(e);
var classes = l.getTypes();
Class c = classes[0];
LibraryElement e = helper.resolve(source);
var l = new Library(e);

group('Library', () {

test('name', () {
expect(l.name, 'ex');
});
});

group('Class', () {

var classes = l.getTypes();
Class A = classes[0];
var B = classes[1];
var C = classes[2];

test('no of classes', () {
expect(classes.length, 1);
expect(classes.length, 3);
});

test('name', () {
expect(c.name, 'A');
expect(A.name, 'A');
});

test('abstract', () {
expect(c.isAbstract, false);
expect(C.isAbstract, true);
});

test('supertype', () {
expect(B.hasSupertype, true);
});

test('interfaces', () {
expect(A.interfaces.length, 0);
});

test('mixins', () {
expect(A.mixins.length, 0);
});

test('get ctors', () {
expect(c.getCtors().length, 1);
expect(A.getCtors().length, 1);
});

test('get static fields', () {
expect(c.getStaticFields().length, 1);
expect(A.getStaticFields().length, 1);
});

test('get instance fields', () {
expect(c.getInstanceFields().length, 3);
expect(A.getInstanceFields().length, 3);
});

test('get accessors', () {
expect(c.getAccessors().length, 1);
expect(A.getAccessors().length, 1);
});

test('get methods', () {
expect(c.getMethods().length, 0);
expect(B.getMethods().length, 1);
});

test('has correct type name', () {
expect(c.typeName, equals('Classes'));
expect(A.typeName, equals('Classes'));
});
});

group('Function', () {

ModelFunction f1 = l.getFunctions()[0];

test('local element', () {
expect(f1.isLocalElement, true);
});

test('is executable', () {
expect(f1.isExecutable, true);
});

test('is static', () {
expect(f1.isStatic, true);
});

test('has correct type name', () {
expect(f1.typeName, equals('Functions'));
});
});

group('TypeParameter', () {

test('has correct type name', () {
var t = new TypeParameter(null, null);
expect(t.typeName, equals('Type Parameters'));
});
test('has correct type name', () {
var t = new TypeParameter(null, null);
expect(t.typeName, equals('Type Parameters'));
});
});

}

Expand Down

0 comments on commit fe5cf41

Please sign in to comment.