<commit_before># encoding: UTF-8

# Author::    <NAME>
# Copyright:: Copyright (c) 2009 <NAME>

class TC_Scalar < Test::Unit::TestCase

	def setup
	end

	def teardown
	end

	def test_text_meta
		f = field '$(foo text 3 1..5)'
		assert_equal(
			3,
			f[:size],
			'Text#initialize should set :size from the token'
		)
		assert_equal(
			1,
			f[:min],
			'Text#initialize should set :min from the range token'
		)
		assert_equal(
			5,
			f[:max],
			'Text#initialize should set :max from the range token'
		)
	end

	def test_text_val_cast
		f = field '$(foo text 3 1..5)'
		f.load 123
		assert_equal(
			'123',
			f.val,
			'Text# should cast the given val to String'
		)
	end

	private

	def field(html)
		meta = nil
		Sofa::Parser.gsub_scalar(html) {|id,m|
			meta = m
			''
		}
		Sofa::Field.instance meta
	end

end<commit_msg>add a case in test_text_val_cast().<commit_after># encoding: UTF-8

# Author::    <NAME>
# Copyright:: Copyright (c) 2009 <NAME>

class TC_Scalar < Test::Unit::TestCase

	def setup
	end

	def teardown
	end

	def test_text_meta
		f = field '$(foo text 3 1..5)'
		assert_equal(
			3,
			f[:size],
			'Text#initialize should set :size from the token'
		)
		assert_equal(
			1,
			f[:min],
			'Text#initialize should set :min from the range token'
		)
		assert_equal(
			5,
			f[:max],
			'Text#initialize should set :max from the range token'
		)
	end

	def test_text_val_cast
		f = field '$(foo text 3 1..5)'
		assert_equal(
			'',
			f.val,
			'Text#val_cast should cast the given val to String'
		)

		f.load 123
		assert_equal(
			'123',
			f.val,
			'Text#val_cast should cast the given val to String'
		)
	end

	private

	def field(html)
		meta = nil
		Sofa::Parser.gsub_scalar(html) {|id,m|
			meta = m
			''
		}
		Sofa::Field.instance meta
	end

end
{'fraction_non_alphanumeric': 0.12156862745098039, 'fraction_numerical': 0.022408963585434174, 'mean_word_length': 2.925274725274725, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3050251', 'n_tokens_mistral': 823, 'n_tokens_neox': 685, 'n_words': 203}