@@ -12,6 +12,9 @@ use crate::{prelude::*, style::Styled, text::StyledGrapheme};
12
12
/// text. When a [`Line`] is rendered, it is rendered as a single line of text, with each [`Span`]
13
13
/// being rendered in order (left to right).
14
14
///
15
+ /// Any newlines in the content are removed when creating a [`Line`] using the constructor or
16
+ /// conversion methods.
17
+ ///
15
18
/// # Constructor Methods
16
19
///
17
20
/// - [`Line::default`] creates a line with empty content and the default style.
@@ -502,13 +505,13 @@ impl<'a> IntoIterator for &'a mut Line<'a> {
502
505
503
506
impl < ' a > From < String > for Line < ' a > {
504
507
fn from ( s : String ) -> Self {
505
- Self :: from ( vec ! [ Span :: from ( s ) ] )
508
+ Self :: raw ( s )
506
509
}
507
510
}
508
511
509
512
impl < ' a > From < & ' a str > for Line < ' a > {
510
513
fn from ( s : & ' a str ) -> Self {
511
- Self :: from ( vec ! [ Span :: from ( s ) ] )
514
+ Self :: raw ( s )
512
515
}
513
516
}
514
517
@@ -803,14 +806,22 @@ mod tests {
803
806
fn from_string ( ) {
804
807
let s = String :: from ( "Hello, world!" ) ;
805
808
let line = Line :: from ( s) ;
806
- assert_eq ! ( vec![ Span :: from( "Hello, world!" ) ] , line. spans) ;
809
+ assert_eq ! ( line. spans, vec![ Span :: from( "Hello, world!" ) ] ) ;
810
+
811
+ let s = String :: from ( "Hello\n world!" ) ;
812
+ let line = Line :: from ( s) ;
813
+ assert_eq ! ( line. spans, vec![ Span :: from( "Hello" ) , Span :: from( "world!" ) ] ) ;
807
814
}
808
815
809
816
#[ test]
810
817
fn from_str ( ) {
811
818
let s = "Hello, world!" ;
812
819
let line = Line :: from ( s) ;
813
- assert_eq ! ( vec![ Span :: from( "Hello, world!" ) ] , line. spans) ;
820
+ assert_eq ! ( line. spans, vec![ Span :: from( "Hello, world!" ) ] ) ;
821
+
822
+ let s = "Hello\n world!" ;
823
+ let line = Line :: from ( s) ;
824
+ assert_eq ! ( line. spans, vec![ Span :: from( "Hello" ) , Span :: from( "world!" ) ] ) ;
814
825
}
815
826
816
827
#[ test]
@@ -820,7 +831,7 @@ mod tests {
820
831
Span :: styled( " world!" , Style :: default ( ) . fg( Color :: Green ) ) ,
821
832
] ;
822
833
let line = Line :: from ( spans. clone ( ) ) ;
823
- assert_eq ! ( spans, line . spans) ;
834
+ assert_eq ! ( line . spans, spans) ;
824
835
}
825
836
826
837
#[ test]
@@ -853,7 +864,7 @@ mod tests {
853
864
fn from_span ( ) {
854
865
let span = Span :: styled ( "Hello, world!" , Style :: default ( ) . fg ( Color :: Yellow ) ) ;
855
866
let line = Line :: from ( span. clone ( ) ) ;
856
- assert_eq ! ( vec![ span] , line . spans ) ;
867
+ assert_eq ! ( line . spans , vec![ span] , ) ;
857
868
}
858
869
859
870
#[ test]
@@ -863,7 +874,7 @@ mod tests {
863
874
Span :: styled( " world!" , Style :: default ( ) . fg( Color :: Green ) ) ,
864
875
] ) ;
865
876
let s: String = line. into ( ) ;
866
- assert_eq ! ( "Hello, world!" , s ) ;
877
+ assert_eq ! ( s , "Hello, world!" ) ;
867
878
}
868
879
869
880
#[ test]
0 commit comments