@@ -791,15 +791,29 @@ suite('p5.Color', function() {
791791 } ) ;
792792 } ) ;
793793
794- suite . todo ( 'p5.Color.prototype.toString' , function ( ) {
795- // var colorStr;
794+ suite ( 'p5.Color.prototype.toString' , function ( ) {
795+ test ( 'should format as #rrggbb hex string' , function ( ) {
796+ const testColor = mockP5Prototype . color ( 153 , 50 , 204 ) ; // darkorchid
797+ const result = testColor . toString ( '#rrggbb' ) ;
798+ assert . equal ( result , '#9932cc' ) ;
799+ } ) ;
796800
797- // beforeEach( function() {
798- // mockP5Prototype.colorMode(mockP5Prototype.RGB, 255, 255, 255, 255);
799- // c = mockP5Prototype.color(128, 0, 128, 128 );
800- // colorStr = c.toString( );
801- // });
801+ test ( 'should format as hex string with "hex" alias' , function ( ) {
802+ const testColor = mockP5Prototype . color ( 153 , 50 , 204 ) ; // darkorchid
803+ const result = testColor . toString ( 'hex' ) ;
804+ assert . equal ( result , '#9932cc' ) ;
805+ } ) ;
802806
803- // NOTE: need some tests here
807+ test ( 'should handle single digit hex values with padding' , function ( ) {
808+ const testColor = mockP5Prototype . color ( 10 , 5 , 15 ) ;
809+ const result = testColor . toString ( '#rrggbb' ) ;
810+ assert . equal ( result , '#0a050f' ) ;
811+ } ) ;
812+
813+ test ( 'should format hex with alpha channel' , function ( ) {
814+ const testColor = mockP5Prototype . color ( 153 , 50 , 204 , 128 ) ;
815+ const result = testColor . toString ( 'hex' ) ;
816+ assert . match ( result , / ^ # [ 0 - 9 a - f ] { 8 } $ / i) ;
817+ } ) ;
804818 } ) ;
805819} ) ;
0 commit comments