summaryrefslogtreecommitdiff
path: root/stringmetric-core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiNumberOnlyFilterSpec.scala
blob: db49d251b7dd267a082bdf4e12e148869a79e636 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package com.rockymadden.stringmetric.filter

import com.rockymadden.stringmetric.ScalaTest
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner

@RunWith(classOf[JUnitRunner])
final class AsciiNumberOnlyFilterSpec extends ScalaTest {
	import AsciiNumberOnlyFilterSpec.Filter

	"AsciiNumberOnlyFilter" should provide {
		"overloaded filter method" when passed {
			"String with mixed characters" should returns {
				"String with non-numbers removed" in {
					Filter.filter("!@#$%^&*()abc123") should equal ("123")
					Filter.filter("123!@#$%^&*()abc") should equal ("123")
					Filter.filter("!@#$%^123&*()abc") should equal ("123")
				}
			}
			"character array with mixed characters" should returns {
				"character array with non-numbers removed" in {
					Filter.filter("!@#$%^&*()abc123".toCharArray) should equal ("123".toCharArray)
					Filter.filter("123!@#$%^&*()abc".toCharArray) should equal ("123".toCharArray)
					Filter.filter("!@#$%^123&*()abc".toCharArray) should equal ("123".toCharArray)
				}
			}
		}
	}
}

object AsciiNumberOnlyFilterSpec {
	private final val Filter = new StringFilterDelegate with AsciiNumberOnlyFilter
}