Skip to content

Chapter 2: Finished the About Strings section #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 16, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
finished writing chapter 2
  • Loading branch information
md-weber committed May 16, 2020
commit 8b37fb0e7611175bc36d79a5c1d366c115b3f067
10 changes: 8 additions & 2 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@ include: package:pedantic/analysis_options.yaml

# For lint rules and documentation, see http://dart-lang.github.io/linter/lints.
# Uncomment to specify additional rules.
# linter:
# rules:
linter:
rules:
info:
- prefer_double_quotes

# - camel_case_types

analyzer:
errors:
- unused_local_variable: info

# exclude:
# - path/to/excluded/files/**
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@ void main() {
*
* Try to fix the following tests
*/
group('Expectations => ', () {
test('Try to fix the following tests', () {});

group('About Asserts', () {
test('Should expect true', () {
print('Your journey begins here: ');
expect(true, false, reason: "Hint: Replace the word 'false' with 'true'");
expect(true, true, reason: "Hint: Replace the word 'false' with 'true'");
});

test('We will compare often values with each other', () {
Expand Down
116 changes: 116 additions & 0 deletions test/chapter_2_about_string_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import 'package:test/test.dart';

const your_answer = null;

void main() {
group('About Strings', () {
test('Double quoted strings are strings', () {
var string = "Hello, world";
expect(your_answer, isA<String>());
});

test('single quoted strings are strings', () {
var string = 'Goodbye, world';
expect(your_answer, isA<String>());
});

test('triple quoted strings are also strings', () {
var string = """Hallo Welt""";
expect(your_answer, isA<String>());
});

test('triple single quoted strings work too', () {
var string = '''Bonjour tout le monde!''';
expect(your_answer, isA<String>());
});

test('raw strings are also strings', () {
var string = r"Konnichi wa, world!";
expect(your_answer, isA<String>());
});

test('use single quotes to create string with double quotes', () {
var string = 'He said, "Go Away."';
assert(your_answer, string);
});

test("use double quotes to create string with single quotes", () {
var string = "Don't";
expect(your_answer, string);
});

test("use backslash for escaping quotes in strings", () {
var a = "He said, \"Don't\"";
var b = 'He said, "Don\'t"';
assert(your_answer, a == b);
});

test("triple quoted strings can span lines", () {
var string = """
Greetings,
Partner!
""";

expect(your_answer, string.length);
});

test("triple quoted strings need less escaping", () {
var a = "Hello \"world\".";
var b = """Hello "world".""";

expect(your_answer, a == b);
});

test("escaping quotes at the end of a triple quoted string", () {
var string = """Hello "world\"""";
expect(your_answer, string);
});

test("plus concatenates strings", () {
var string = "Hello" + ", " + "World";
expect(your_answer, string);
});

test("\$ is a better concatination", () {
var a = "Hello";
var b = "World";

expect(your_answer, "$a, $b");
});

test("With \${} you are able to access attributes and concatinate them",
() {
var string = "Concatination is great!";
expect(your_answer, "${string.length}");
});

test("adjacent strings are concatenated automatically", () {
var string = "Hello" ", " "World";
expect(your_answer, string);
});

test("plus will not modify the original strings", () {
var foo = "Hello, ";
var bar = "World";
var string = foo + bar;

expect(your_answer, foo);
expect(your_answer, bar);
});

test("plus equals will append to the end of the string", () {
var foo = "Hello, ";
var bar = "World";
foo += bar;
expect(your_answer, foo);
});

test("plus equals also leaves original string unmodified", () {
var original = "Hello, ";
var foo = original;
var bar = "World";
foo += bar;
expect(your_answer, original);
});
});
}
Empty file removed test/chapter_2_string_test.dart
Empty file.