Runtime assertions for Ruby literal.fun
ruby
5
fork

Configure Feed

Select the types of activity you want to include in your feed.

Init

Joel Drapper 9bbda9d0

+785
+8
.gitignore
··· 1 + /.bundle/ 2 + /.yardoc 3 + /_yardoc/ 4 + /coverage/ 5 + /doc/ 6 + /pkg/ 7 + /spec/reports/ 8 + /tmp/
+5
CHANGELOG.md
··· 1 + ## [Unreleased] 2 + 3 + ## [0.1.0] - 2023-05-03 4 + 5 + - Initial release
+84
CODE_OF_CONDUCT.md
··· 1 + # Contributor Covenant Code of Conduct 2 + 3 + ## Our Pledge 4 + 5 + We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 + 7 + We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community. 8 + 9 + ## Our Standards 10 + 11 + Examples of behavior that contributes to a positive environment for our community include: 12 + 13 + * Demonstrating empathy and kindness toward other people 14 + * Being respectful of differing opinions, viewpoints, and experiences 15 + * Giving and gracefully accepting constructive feedback 16 + * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience 17 + * Focusing on what is best not just for us as individuals, but for the overall community 18 + 19 + Examples of unacceptable behavior include: 20 + 21 + * The use of sexualized language or imagery, and sexual attention or 22 + advances of any kind 23 + * Trolling, insulting or derogatory comments, and personal or political attacks 24 + * Public or private harassment 25 + * Publishing others' private information, such as a physical or email 26 + address, without their explicit permission 27 + * Other conduct which could reasonably be considered inappropriate in a 28 + professional setting 29 + 30 + ## Enforcement Responsibilities 31 + 32 + Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful. 33 + 34 + Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate. 35 + 36 + ## Scope 37 + 38 + This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. 39 + 40 + ## Enforcement 41 + 42 + Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at joel@drapper.me. All complaints will be reviewed and investigated promptly and fairly. 43 + 44 + All community leaders are obligated to respect the privacy and security of the reporter of any incident. 45 + 46 + ## Enforcement Guidelines 47 + 48 + Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct: 49 + 50 + ### 1. Correction 51 + 52 + **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community. 53 + 54 + **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested. 55 + 56 + ### 2. Warning 57 + 58 + **Community Impact**: A violation through a single incident or series of actions. 59 + 60 + **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban. 61 + 62 + ### 3. Temporary Ban 63 + 64 + **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior. 65 + 66 + **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban. 67 + 68 + ### 4. Permanent Ban 69 + 70 + **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals. 71 + 72 + **Consequence**: A permanent ban from any sort of public interaction within the community. 73 + 74 + ## Attribution 75 + 76 + This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0, 77 + available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. 78 + 79 + Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity). 80 + 81 + [homepage]: https://www.contributor-covenant.org 82 + 83 + For answers to common questions about this code of conduct, see the FAQ at 84 + https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
+9
Gemfile
··· 1 + # frozen_string_literal: true 2 + 3 + source "https://rubygems.org" 4 + 5 + # Specify your gem's dependencies in strict_attributes.gemspec 6 + gemspec 7 + 8 + gem "zeitwerk" 9 + gem "green_dots", git: "https://github.com/joeldrapper/green_dots.git"
+29
Gemfile.lock
··· 1 + GIT 2 + remote: https://github.com/joeldrapper/green_dots.git 3 + revision: 776745d38c9523e403b445eeef8b374ffb130f8b 4 + specs: 5 + green_dots (0.1.0) 6 + concurrent-ruby 7 + zeitwerk 8 + 9 + PATH 10 + remote: . 11 + specs: 12 + literal (0.1.0) 13 + 14 + GEM 15 + remote: https://rubygems.org/ 16 + specs: 17 + concurrent-ruby (1.2.2) 18 + zeitwerk (2.6.8) 19 + 20 + PLATFORMS 21 + arm64-darwin-22 22 + 23 + DEPENDENCIES 24 + green_dots! 25 + literal! 26 + zeitwerk 27 + 28 + BUNDLED WITH 29 + 2.4.12
+21
LICENSE.txt
··· 1 + The MIT License (MIT) 2 + 3 + Copyright (c) 2023 Joel Drapper 4 + 5 + Permission is hereby granted, free of charge, to any person obtaining a copy 6 + of this software and associated documentation files (the "Software"), to deal 7 + in the Software without restriction, including without limitation the rights 8 + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 + copies of the Software, and to permit persons to whom the Software is 10 + furnished to do so, subject to the following conditions: 11 + 12 + The above copyright notice and this permission notice shall be included in 13 + all copies or substantial portions of the Software. 14 + 15 + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 + THE SOFTWARE.
+112
README.md
··· 1 + # Literal 2 + 3 + ## Basic Usage 4 + 5 + ### Mixin 6 + 7 + ```ruby 8 + class User 9 + include Literal 10 + 11 + attribute :name, String 12 + attribute :age, Integer 13 + end 14 + ``` 15 + 16 + ### Struct 17 + 18 + ```ruby 19 + class Person < Literal::Struct 20 + attribute :name, String 21 + attribute :age, Integer 22 + end 23 + ``` 24 + 25 + ### Data 26 + 27 + ```ruby 28 + class Person < Literal::Data 29 + attribute :name, String 30 + attribute :age, Integer 31 + end 32 + ``` 33 + 34 + ## Special Types 35 + 36 + ### Union 37 + 38 + ```ruby 39 + _Union(String, Symbol) 40 + ``` 41 + 42 + ### Boolean 43 + 44 + ```ruby 45 + _Boolean 46 + ``` 47 + 48 + ### Maybe 49 + 50 + ```ruby 51 + _Maybe(String) 52 + ``` 53 + 54 + ### Array 55 + 56 + ```ruby 57 + _Array(String) 58 + ``` 59 + 60 + ### Set 61 + 62 + ```ruby 63 + _Set(String) 64 + ``` 65 + 66 + ### Enumerable 67 + 68 + ```ruby 69 + _Enumerable(String) 70 + ``` 71 + 72 + ### Tuple 73 + An Enumerable containing exactly the specified types in order. 74 + 75 + ```ruby 76 + _Tuple(String, Integer) 77 + ``` 78 + 79 + ### Hash 80 + 81 + ```ruby 82 + _Hash(String, Integer) 83 + ``` 84 + 85 + ### Interface 86 + ```ruby 87 + _Interface(:to_s) 88 + ``` 89 + 90 + ### Class 91 + 92 + ```ruby 93 + _Class(RuntimeError) 94 + ``` 95 + 96 + ### Module 97 + 98 + ```ruby 99 + _Module(Enumerable) 100 + ``` 101 + 102 + ### Integer 103 + You can of course just use `Integer` to specify an integer type. The special type `_Integer` allows you to limit that type with a range, while verifying that it's an integer and not something else that matches the range such as a float. 104 + 105 + ``` 106 + _Integer(18..) 107 + ``` 108 + 109 + You can use these types together. 110 + ```ruby 111 + _Maybe(Union(String, Symbol, Interface(:to_s), Interface(:to_str), Tuple(String, Symbol))) 112 + ```
+12
Rakefile
··· 1 + # frozen_string_literal: true 2 + 3 + require "bundler/gem_tasks" 4 + require "rake/testtask" 5 + 6 + Rake::TestTask.new(:test) do |t| 7 + t.libs << "test" 8 + t.libs << "lib" 9 + t.test_files = FileList["test/**/test_*.rb"] 10 + end 11 + 12 + task default: :test
+11
bin/console
··· 1 + #!/usr/bin/env ruby 2 + # frozen_string_literal: true 3 + 4 + require "bundler/setup" 5 + require "literal" 6 + 7 + # You can add fixtures and/or initialization code here to make experimenting 8 + # with your gem easier. You can also use a different console, if you like. 9 + 10 + require "irb" 11 + IRB.start(__FILE__)
+8
bin/setup
··· 1 + #!/usr/bin/env bash 2 + set -euo pipefail 3 + IFS=$'\n\t' 4 + set -vx 5 + 6 + bundle install 7 + 8 + # Do any other automated setup that you need to do here
+17
lib/literal.rb
··· 1 + # frozen_string_literal: true 2 + 3 + require_relative "literal/version" 4 + 5 + module Literal 6 + Loader = Zeitwerk::Loader.for_gem.tap(&:setup) 7 + 8 + module Error; end 9 + 10 + class TypeError < ::TypeError 11 + include Error 12 + end 13 + 14 + class ArgumentError < ::ArgumentError 15 + include Error 16 + end 17 + end
+33
lib/literal/attributes.rb
··· 1 + module Literal::Attributes 2 + extend Literal::Types 3 + 4 + def attribute(name, type, reader: false, writer: :private) 5 + __attributes__ << name 6 + 7 + writer_name = :"#{name}=" 8 + ivar_name = :"@#{name}" 9 + 10 + define_method writer_name do |value| 11 + raise Literal::TypeError, "Expected `#{value.inspect}` to be a `#{type.inspect}`." unless type === value 12 + instance_variable_set(ivar_name, value) 13 + end 14 + 15 + private writer_name unless writer == :public 16 + 17 + if reader 18 + attr_reader name 19 + private name unless reader == :public 20 + end 21 + 22 + name 23 + end 24 + 25 + def __attributes__ 26 + return @__attributes__ if defined?(@__attributes__) 27 + @__attributes__ = superclass.is_a?(self) ? superclass.__attributes__.dup : [] 28 + end 29 + 30 + def self.extended(base) 31 + base.include(Literal::Initializer) 32 + end 33 + end
+12
lib/literal/data.rb
··· 1 + class Literal::Data < Literal::Struct 2 + def initialize(...) 3 + super 4 + @attributes.each(&:freeze) 5 + @attributes.freeze 6 + freeze 7 + end 8 + 9 + def dup(**attributes) 10 + self.class.new(**@attributes.merge(attributes)) 11 + end 12 + end
+11
lib/literal/initializer.rb
··· 1 + module Literal::Initializer 2 + def initialize(**attributes) 3 + self.class.__attributes__.each do |name| 4 + attributes[name] ||= nil 5 + end 6 + 7 + attributes.each do |name, value| 8 + send("#{name}=", value) 9 + end 10 + end 11 + end
+22
lib/literal/model.rb
··· 1 + class Literal::Model 2 + extend Literal::Types 3 + include Literal::Initializer 4 + 5 + def self.__attributes__ 6 + return @required_attributes if defined?(@required_attributes) 7 + @required_attributes = superclass.is_a?(self) ? superclass.required_attributes.dup : [] 8 + end 9 + 10 + def self.attribute(name, type) 11 + __attributes__ << name 12 + 13 + writer_name = :"#{name}=" 14 + 15 + define_method writer_name do |value| 16 + raise Literal::TypeError, "Expected #{name}: `#{value.inspect}` to be: `#{type.inspect}`." unless type === value 17 + super(value) 18 + end 19 + 20 + name 21 + end 22 + end
+35
lib/literal/struct.rb
··· 1 + class Literal::Struct 2 + extend Literal::Types 3 + include Literal::Initializer 4 + 5 + def initialize(...) 6 + @attributes = {} 7 + super 8 + end 9 + 10 + def self.__attributes__ 11 + return @__attributes__ if defined?(@__attributes__) 12 + @__attributes__ = superclass.is_a?(self) ? superclass.__attributes__.dup : [] 13 + end 14 + 15 + def self.attribute(name, type, writer: :private) 16 + __attributes__ << name 17 + 18 + writer_name = :"#{name}=" 19 + 20 + define_method writer_name do |value| 21 + raise Literal::TypeError, "Expected #{name}: `#{value.inspect}` to be: `#{type.inspect}`." unless type === value 22 + @attributes[name] = value 23 + end 24 + 25 + define_method name do 26 + @attributes[name] 27 + end 28 + 29 + name 30 + end 31 + 32 + def to_h 33 + @attributes.dup 34 + end 35 + end
+56
lib/literal/types.rb
··· 1 + module Literal::Types 2 + def _Union(*types) 3 + raise Literal::ArgumentError, "Union type must have at least two types." if types.size < 2 4 + Literal::Types::UnionType.new(*types) 5 + end 6 + 7 + def _Array(type) 8 + Literal::Types::ArrayType.new(type) 9 + end 10 + 11 + def _Set(type) 12 + Literal::Types::SetType.new(type) 13 + end 14 + 15 + def _Enumerable(type) 16 + Literal::Types::EnumerableType.new(type) 17 + end 18 + 19 + def _Hash(key_type, value_type) 20 + Literal::Types::HashType.new(key_type, value_type) 21 + end 22 + 23 + def _Interface(*methods) 24 + raise Literal::ArgumentError, "Interface type must have at least one method." if methods.size < 1 25 + Literal::Types::InterfaceType.new(*methods) 26 + end 27 + 28 + def _Maybe(type) 29 + _Union(type, nil) 30 + end 31 + 32 + def _Any 33 + Literal::Types::AnyType 34 + end 35 + 36 + def _Boolean 37 + Literal::Types::BooleanType 38 + end 39 + 40 + def _Class(type) 41 + Literal::Types::ClassType.new(type) 42 + end 43 + 44 + def _Tuple(*types) 45 + raise Literal::ArgumentError, "Tuple type must have at least one type." if types.size < 1 46 + Literal::Types::TupleType.new(*types) 47 + end 48 + 49 + def _Integer(range) 50 + Literal::Types::IntegerType.new(range) 51 + end 52 + 53 + def _Float(range) 54 + Literal::Types::FloatType.new(range) 55 + end 56 + end
+5
lib/literal/types/any_type.rb
··· 1 + module Literal::Types::AnyType 2 + def self.===(value) 3 + true 4 + end 5 + end
+13
lib/literal/types/array_type.rb
··· 1 + class Literal::Types::ArrayType 2 + def initialize(type) 3 + @type = type 4 + end 5 + 6 + def inspect 7 + "Array(#{@type.inspect})" 8 + end 9 + 10 + def ===(value) 11 + value.is_a?(::Array) && value.all? { |item| @type === item } 12 + end 13 + end
+1
lib/literal/types/boolean_type.rb
··· 1 + Literal::Types::BooleanType = Literal::Types::UnionType.new(true, false)
+13
lib/literal/types/class_type.rb
··· 1 + class Literal::Types::ClassType 2 + def initialize(type) 3 + @type = type 4 + end 5 + 6 + def inspect 7 + "Class(#{@type.name})" 8 + end 9 + 10 + def ===(value) 11 + value.is_a?(::Class) && (value == @type || value < @type) 12 + end 13 + end
+13
lib/literal/types/enumerable_type.rb
··· 1 + class Literal::Types::EnumerableType 2 + def initialize(type) 3 + @type = type 4 + end 5 + 6 + def inspect 7 + "Enumerable(#{@type.inspect})" 8 + end 9 + 10 + def ===(value) 11 + value.is_a?(::Enumerable) && value.all? { |item| @type === item } 12 + end 13 + end
+13
lib/literal/types/float_type.rb
··· 1 + class Literal::Types::FloatType 2 + def initialize(range) 3 + @range = range 4 + end 5 + 6 + def inspect 7 + "Float(#{@range})" 8 + end 9 + 10 + def ===(other) 11 + other.is_a?(::Float) && @range === other 12 + end 13 + end
+14
lib/literal/types/hash_type.rb
··· 1 + class Literal::Types::HashType 2 + def initialize(key_type, value_type) 3 + @key_type = key_type 4 + @value_type = value_type 5 + end 6 + 7 + def inspect 8 + "Hash(#{@key_type.inspect}, #{@value_type.inspect})" 9 + end 10 + 11 + def ===(value) 12 + value.is_a?(::Hash) && value.all? { |key, value| @key_type === key && @value_type === value } 13 + end 14 + end
+13
lib/literal/types/integer_type.rb
··· 1 + class Literal::Types::IntegerType 2 + def initialize(range) 3 + @range = range 4 + end 5 + 6 + def inspect 7 + "Integer(#{@range})" 8 + end 9 + 10 + def ===(other) 11 + other.is_a?(::Integer) && @range === other 12 + end 13 + end
+13
lib/literal/types/interface_type.rb
··· 1 + class Literal::Types::InterfaceType 2 + def initialize(*methods) 3 + @methods = methods 4 + end 5 + 6 + def inspect 7 + "Interface(#{@methods.map(&:inspect).join(", ")})" 8 + end 9 + 10 + def ===(other) 11 + @methods.all? { |method| other.respond_to?(method) } 12 + end 13 + end
+13
lib/literal/types/set_type.rb
··· 1 + class Literal::Types::SetType 2 + def initialize(type) 3 + @type = type 4 + end 5 + 6 + def inspect 7 + "Set(#{@type.inspect})" 8 + end 9 + 10 + def ===(value) 11 + value.is_a?(::Set) && value.all? { |item| @type === item } 12 + end 13 + end
+13
lib/literal/types/tuple_type.rb
··· 1 + class Literal::Types::TupleType 2 + def initialize(*types) 3 + @types = types 4 + end 5 + 6 + def inspect 7 + "Tuple(#{@types.map(&:inspect).join(", ")})" 8 + end 9 + 10 + def ===(value) 11 + value.is_a?(::Enumerable) && value.size == @types.size && value.zip(@types).all? { |value, type| type === value } 12 + end 13 + end
+13
lib/literal/types/union_type.rb
··· 1 + class Literal::Types::UnionType 2 + def initialize(*types) 3 + @types = types 4 + end 5 + 6 + def inspect 7 + "Union(#{@types.map(&:inspect).join(", ")})" 8 + end 9 + 10 + def ===(value) 11 + @types.any? { |type| type === value } 12 + end 13 + end
+5
lib/literal/version.rb
··· 1 + # frozen_string_literal: true 2 + 3 + module Literal 4 + VERSION = "0.1.0" 5 + end
+37
literal.gemspec
··· 1 + # frozen_string_literal: true 2 + 3 + require_relative "lib/literal/version" 4 + 5 + Gem::Specification.new do |spec| 6 + spec.name = "literal" 7 + spec.version = Literal::VERSION 8 + spec.authors = ["Joel Drapper"] 9 + spec.email = ["joel@drapper.me"] 10 + 11 + spec.summary = "Strict Attributes is a gem that allows you to define strict attributes on your models." 12 + spec.description = "Strict Attributes is a gem that allows you to define strict attributes on your models." 13 + spec.homepage = "https://github.com/joeldrapper/literal" 14 + spec.license = "MIT" 15 + spec.required_ruby_version = ">= 2.6.0" 16 + 17 + spec.metadata["homepage_uri"] = spec.homepage 18 + spec.metadata["source_code_uri"] = "https://github.com/joeldrapper/literal" 19 + spec.metadata["changelog_uri"] = "https://github.com/joeldrapper/literal/blob/master/CHANGELOG.md" 20 + 21 + # Specify which files should be added to the gem when it is released. 22 + # The `git ls-files -z` loads the files in the RubyGem that have been added into git. 23 + spec.files = Dir.chdir(__dir__) do 24 + `git ls-files -z`.split("\x0").reject do |f| 25 + (File.expand_path(f) == __FILE__) || f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor]) 26 + end 27 + end 28 + spec.bindir = "exe" 29 + spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) } 30 + spec.require_paths = ["lib"] 31 + 32 + # Uncomment to register a new dependency of your gem 33 + # spec.add_dependency "example-gem", "~> 1.0" 34 + 35 + # For more information and examples about making a new gem, check out our 36 + # guide at: https://bundler.io/guides/creating_gem.html 37 + end
+18
test/literal/struct.rb
··· 1 + class Person < Literal::Struct 2 + attribute :name, String 3 + attribute :age, Integer 4 + end 5 + 6 + test do 7 + expect { 8 + Person.new(name: "John", age: 42) 9 + }.not_to_raise 10 + end 11 + 12 + test do 13 + expect { 14 + Person.new(name: 1, age: "Hello") 15 + }.to_raise(Literal::TypeError) do |error| 16 + expect(error.message) == "Expected name: `1` to be: `String`." 17 + end 18 + end
+102
test/literal/types.rb
··· 1 + include Literal::Types 2 + 3 + test "Any" do 4 + assert _Any === nil 5 + assert _Any === 0 6 + assert _Any === "a" 7 + assert _Any === :a 8 + assert _Any === [] 9 + assert _Any === {} 10 + assert _Any === Object.new 11 + assert _Any === Class.new 12 + end 13 + 14 + test "Array" do 15 + assert _Array(String) === ["a", "b", "c"] 16 + 17 + refute _Array(String) === ["a", "b", 1] 18 + refute _Array(String) === Set.new(["a", "b", "c"]) 19 + end 20 + 21 + test "Boolean" do 22 + assert _Boolean === true 23 + assert _Boolean === false 24 + 25 + refute _Boolean === nil 26 + refute _Boolean === 0 27 + refute _Boolean === "true" 28 + refute _Boolean === "false" 29 + refute _Boolean === [true] 30 + refute _Boolean === [false] 31 + refute _Boolean === TrueClass 32 + refute _Boolean === FalseClass 33 + end 34 + 35 + test "Class" do 36 + assert _Class(StandardError) === StandardError 37 + assert _Class(StandardError) === RuntimeError 38 + 39 + refute _Class(StandardError) === Exception 40 + refute _Class(StandardError) === Object 41 + refute _Class(StandardError) === Class 42 + end 43 + 44 + test "Enumerable" do 45 + assert _Enumerable(String) === ["a", "b", "c"] 46 + assert _Enumerable(String) === Set.new(["a", "b", "c"]) 47 + 48 + refute _Enumerable(String) === ["a", "b", 1] 49 + refute _Enumerable(String) === Set.new(["a", "b", 1]) 50 + end 51 + 52 + test "Float" do 53 + assert _Float(0..1) === 0.0 54 + assert _Float(0..1) === 0.5 55 + assert _Float(0..1) === 1.0 56 + 57 + refute _Float(0..1) === -1.0 58 + refute _Float(0..1) === 1.1 59 + end 60 + 61 + test "Hash" do 62 + assert _Hash(String, Integer) === {"a" => 1, "b" => 2, "c" => 3} 63 + 64 + refute _Hash(String, Integer) === {"a" => 1, "b" => 2, 3 => "c"} 65 + end 66 + 67 + test "Integer" do 68 + assert _Integer(1..2) === 1 69 + assert _Integer(1..2) === 2 70 + 71 + refute _Integer(1..2) === 0 72 + refute _Integer(1..2) === 3 73 + refute _Integer(1..2) === 1.0 74 + end 75 + 76 + test "Interface" do 77 + assert _Interface(:to_a) === { a: 1 } 78 + 79 + refute _Interface(:to_a) === "" 80 + end 81 + 82 + test "Set" do 83 + assert _Set(String) === Set.new(["a", "b", "c"]) 84 + 85 + refute _Set(String) === Set.new(["a", "b", 1]) 86 + refute _Set(String) === ["a", "b", "c"] 87 + end 88 + 89 + test "Tuple" do 90 + assert _Tuple(String, Integer) === ["a", 1] 91 + 92 + refute _Tuple(String, Integer) === ["a", "b"] 93 + refute _Tuple(String, Integer) === ["a", 1, "b"] 94 + end 95 + 96 + test "Union" do 97 + assert _Union(String, Integer) === "a" 98 + assert _Union(String, Integer) === 1 99 + 100 + refute _Union(String, Integer) === :a 101 + refute _Union(String, Integer) === 1.0 102 + end
+1
test/support/helper.rb
··· 1 + require "literal"