blob: 0aee2fc5ad539618ccadfe5ed0ebc6e920ed689c [file] [log] [blame]
// Copyright (C) 2016 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package assert_test
import "android.googlesource.com/platform/tools/gpu/framework/assert"
// An example of testing string equality
func ExampleStringEquals() {
ctx := assert.Context(nil)
assert.With(ctx).ThatString("a").Equals("a")
assert.With(ctx).ThatString("a").Equals("b")
assert.With(ctx).ThatString("a").NotEquals("a")
assert.With(ctx).ThatString("a").NotEquals("b")
// Output:
// Error
// Differs from 'a'
// Got: 'a'
// Expected: 'b'
// Error
// Got: 'a'
// Expected a non equal string
}
// An example of testing partial string equality
func ExampleStringFragments() {
ctx := assert.Context(nil)
assert.With(ctx).ThatString("abc").Contains("b")
assert.With(ctx).ThatString("abc").Contains("d")
assert.With(ctx).ThatString("abc").HasPrefix("a")
assert.With(ctx).ThatString("abc").HasPrefix("b")
assert.With(ctx).ThatString("abc").HasSuffix("c")
assert.With(ctx).ThatString("abc").HasSuffix("b")
// Output:
// Error
// Got: 'abc'
// Does not contain 'd'
// Error
// Got: 'abc'
// Does not start with 'b'
// Error
// Got: 'abc'
// Does not end with 'b'
}
// An example of testing non strings as strings
func ExampleStringTypes() {
ctx := assert.Context(nil)
assert.With(ctx).ThatString([]byte{'a', 'b', 'c'}).Equals("a")
assert.With(ctx).ThatString(10).Equals("10")
// Output:
// Error
// Longer by 'bc'
// Got: 'abc'
// Expected: 'a'
}