2013-07-29 1 views
3

왜 ScalaTest 2.0.M5b로 컴파일되지 않습니까?시퀀스 정렬시 ScalaTest 테스트

overloaded method value should with alternatives: (beWord: NewCollectionsSpec.this.BeWord)NewCollectionsSpec.this.ResultOfBeWordForAnyRef[scala.collection.GenSeq[Int]] <and> (notWord: 
NewCollectionsSpec.this.NotWord)NewCollectionsSpec.this.ResultOfNotWordForAnyRef[scala.collection.GenSeq[Int]] <and> (haveWord: 
NewCollectionsSpec.this.HaveWord)NewCollectionsSpec.this.ResultOfHaveWordForSeq[Int] <and> (rightMatcher: org.scalatest.matchers.Matcher[scala.collection.GenSeq[Int]])Unit cannot be applied to 
(org.scalatest.matchers.Matcher[Seq[Int]]) 
+0

다음을 컴파일합니다. 'convertToAnyRefShouldWrapper (sorted [Int]) 여야합니다.' –

+0

정말입니까? 이것은 컴파일되지 않습니다. ScalaTest 버전에 따라 다를 수 있습니다. –

+0

뷰 바인딩 된 버그를 수정하는 코드를 업데이트했습니다. 죄송합니다. –

답변

1

s: Seq[Int] 암시 SeqShouldWrapper[GenSeq[Int]]로 변환되었다

import org.scalatest.matchers.MatchResult 
import org.scalatest.matchers.BeMatcher 
import org.scalatest.matchers.ShouldMatchers._ 

def sorted[T <% Ordered[T]] = new BeMatcher[Seq[T]] { 
    override def apply(s: Seq[T]) = 
    MatchResult(
     s match { 
      case Seq(h, [email protected]_*) => s.zip(t).forall{ case (x,y) => x < y } 
      case _ => true 
     }, 
     s + " was not sorted", 
     s + " was sorted") 
} 

val s = Seq(1, 2, 3) 
s should be (sorted[Int]) 

내가 얻을 오류입니다. Matcher[Seq[Int]]과 호환되는 대체 should이 없습니다. 하지만 def should(rightMatcher: Matcher[GenSeq[T]])입니다. 당신은 당신이 유형의 제약 조건을 경우 matcher 변경한다면, 모든 컴파일 :

def sorted[T <% Ordered[T]] = new BeMatcher[GenSeq[T]] { 
    def apply(s: GenSeq[T]) = 
    MatchResult(
     s match { 
     case Seq(h, [email protected]_*) => s.zip(t).forall { 
      case (x, y) => x < y 
     } 
     case _ => true 
     }, 
     s + " was not sorted", 
     s + " was sorted") 
} 
4

Scalatest 이미 바로 그러한 정규 제공 :

seq shouldBe sorted 

주 그 비슷한 보이는 코드

seq should be sorted 

컴파일되지 않습니다.