rubyment 0.6.25524941 → 0.6.25535011
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/rubyment.rb +551 -113
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8b3bf33d8dfd18d9b8da23e205233274baf4248f
|
4
|
+
data.tar.gz: 14d1d282699c9976f36e26c69d10bd1c837c79b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ddedfdd92d9e9fc379c6a06e6fd2d4f5755c61a7c9baeca65e6f6ed73fa1e2f9636e451a51a6f0b5c4ad06edc0d3825b791de4ac59b8cf6e08152d73e44c8bf6
|
7
|
+
data.tar.gz: 4000290e456744382005e58531029242aa21326188279cd781a4af7f6a2938d1c34386c63b7f92c6a51d17727ce26af39fb52810b4fd3a73bd1c52adc66bec4b
|
data/lib/rubyment.rb
CHANGED
@@ -52,9 +52,22 @@ class Object
|
|
52
52
|
end
|
53
53
|
|
54
54
|
|
55
|
-
# returns +!self+
|
56
|
-
|
57
|
-
|
55
|
+
# returns +!self+, unless +unless_condition+
|
56
|
+
# is +true+; in such case returns +self+.
|
57
|
+
# e.g: +false.negate_me true+ returns
|
58
|
+
# +false+.
|
59
|
+
# (by default, if no params are given,
|
60
|
+
# just # negates +self+)
|
61
|
+
def negate_me condition=true
|
62
|
+
# STDERR.puts "negate_me"
|
63
|
+
(condition) && (
|
64
|
+
# STDERR.puts "condition"
|
65
|
+
# STDERR.puts "#{self.inspect}"
|
66
|
+
!self
|
67
|
+
) || (!condition) && (
|
68
|
+
# STDERR.puts "!condition"
|
69
|
+
self
|
70
|
+
)
|
58
71
|
end
|
59
72
|
end
|
60
73
|
|
@@ -860,7 +873,7 @@ module RubymentModule
|
|
860
873
|
end
|
861
874
|
|
862
875
|
|
863
|
-
# makes a rest request
|
876
|
+
# makes a rest request
|
864
877
|
# @param [Array] +args+, an +Array+ whose elements are expected to be:
|
865
878
|
# +url+:: [String]
|
866
879
|
# +payload+:: [String]
|
@@ -870,8 +883,13 @@ module RubymentModule
|
|
870
883
|
# +auth_user+:: [String, nil] username for basic authentication method
|
871
884
|
# +password+:: [String, nil] password for basic authentication method. Will prompt without echo if +nil+ and +auth_user+ is not +nil+
|
872
885
|
# +timeout+:: [Fixnum]
|
873
|
-
#
|
874
|
-
|
886
|
+
# +debug+:: [Object] if calling the object +nne+ method returns a +false+ value, won't print debug information
|
887
|
+
# @return [Array] returns an +Array+ whose elements are :
|
888
|
+
# +response+:: [String]
|
889
|
+
# +response+:: [Object] as returned by +RestClient::Request.execute+. Note that this is a dangerous object for printing, be aware.
|
890
|
+
# +http_response_object+:: [Net::HTTPResponse]
|
891
|
+
# +http_response_object.code+:: [String]
|
892
|
+
def rest_response__request_base args=ARGV
|
875
893
|
require 'base64'
|
876
894
|
require 'rest-client'
|
877
895
|
|
@@ -885,8 +903,13 @@ module RubymentModule
|
|
885
903
|
auth_user,
|
886
904
|
password,
|
887
905
|
timeout,
|
906
|
+
debug,
|
888
907
|
reserved = args
|
889
908
|
|
909
|
+
debug = debug.nne
|
910
|
+
debug.nne && (stderr.puts "{#{__method__} starting")
|
911
|
+
debug && (stderr.puts "args=#{args.inspect}")
|
912
|
+
|
890
913
|
auth_user = auth_user.nne
|
891
914
|
password = password.nne
|
892
915
|
method = method.nne :get
|
@@ -896,8 +919,41 @@ module RubymentModule
|
|
896
919
|
auth_user && (input_single_line_non_echo [password])
|
897
920
|
].join ":"
|
898
921
|
auth_user && (headers["Authorization"] = "Basic #{base64_auth}")
|
899
|
-
|
900
|
-
|
922
|
+
response,
|
923
|
+
request,
|
924
|
+
http_response_object = RestClient::Request.execute(
|
925
|
+
:method => method,
|
926
|
+
:url => url,
|
927
|
+
:payload => payload,
|
928
|
+
:headers => headers,
|
929
|
+
:verify_ssl => verify_ssl,
|
930
|
+
:timeout => timeout
|
931
|
+
) {|*args| args}
|
932
|
+
rv = [
|
933
|
+
response.to_s,
|
934
|
+
request,
|
935
|
+
http_response_object,
|
936
|
+
http_response_object.code,
|
937
|
+
]
|
938
|
+
debug && (stderr.puts "will return #{rv.map(&:to_s)}")
|
939
|
+
debug && (stderr.puts "#{__method__} returning}")
|
940
|
+
rv
|
941
|
+
end
|
942
|
+
|
943
|
+
|
944
|
+
# makes a rest request.
|
945
|
+
# @param [Array] +args+, an +Array+ whose elements are expected to be:
|
946
|
+
# +url+:: [String]
|
947
|
+
# +payload+:: [String]
|
948
|
+
# +verify_ssl+:: [Boolean]
|
949
|
+
# +headers+:: [Hash] +"Authorization"+ key will be added to it if +auth_user+ is given.
|
950
|
+
# +method+:: [HTTP method] one of +:get+, +:method+, +:post+ or +:delete+
|
951
|
+
# +auth_user+:: [String, nil] username for basic authentication method
|
952
|
+
# +password+:: [String, nil] password for basic authentication method. Will prompt without echo if +nil+ and +auth_user+ is not +nil+
|
953
|
+
# +timeout+:: [Fixnum]
|
954
|
+
# @return [String] the response
|
955
|
+
def rest_request args=ARGV
|
956
|
+
(rest_response__request_base args).first
|
901
957
|
end
|
902
958
|
|
903
959
|
|
@@ -1968,6 +2024,7 @@ require '#{gem_name}'
|
|
1968
2024
|
gem_is_current_file && (
|
1969
2025
|
FileUtils.mkdir_p 'lib'
|
1970
2026
|
file_backup "lib/#{gem_name}.rb", "lib/"
|
2027
|
+
# FIX ME: accept true
|
1971
2028
|
save_file gem_is_current_file, "lib/#{gem_name}.rb"
|
1972
2029
|
)
|
1973
2030
|
|
@@ -3509,51 +3566,6 @@ n8mFEtUKobsK
|
|
3509
3566
|
end
|
3510
3567
|
|
3511
3568
|
|
3512
|
-
# test #rest_request
|
3513
|
-
# for now, the parameters must still be hardcoded.
|
3514
|
-
def test__rest_request__with_ayt args=ARGV
|
3515
|
-
require 'json'
|
3516
|
-
stderr = @memory[:stderr]
|
3517
|
-
|
3518
|
-
url = "https://owl.loftweb.nl:55031/4/3-roOomydev"
|
3519
|
-
json =<<-ENDHEREDOC
|
3520
|
-
{
|
3521
|
-
"operation" : "AYT",
|
3522
|
-
"version" : {
|
3523
|
-
"client" : "X",
|
3524
|
-
"protocol" : {
|
3525
|
-
"domain_model" : "4",
|
3526
|
-
"API" : "3"
|
3527
|
-
}
|
3528
|
-
}
|
3529
|
-
}
|
3530
|
-
ENDHEREDOC
|
3531
|
-
payload = "#{json}"
|
3532
|
-
|
3533
|
-
auth_user = "web"
|
3534
|
-
password = "vadim"
|
3535
|
-
method = :post
|
3536
|
-
method = :get
|
3537
|
-
timeout = 600
|
3538
|
-
verify_ssl = true
|
3539
|
-
payload = "#{json}"
|
3540
|
-
headers = ""
|
3541
|
-
request_execution = send :rest_request, [
|
3542
|
-
url,
|
3543
|
-
payload,
|
3544
|
-
verify_ssl,
|
3545
|
-
headers,
|
3546
|
-
method,
|
3547
|
-
auth_user,
|
3548
|
-
password,
|
3549
|
-
timeout,
|
3550
|
-
]
|
3551
|
-
parsed_json = JSON.parse request_execution.to_s
|
3552
|
-
stderr.puts parsed_json
|
3553
|
-
[parsed_json]
|
3554
|
-
end
|
3555
|
-
|
3556
|
-
|
3557
3569
|
# test for functions that adds syntatic sugar to
|
3558
3570
|
# exceptions.
|
3559
3571
|
def test__rune_functions args = ARGV
|
@@ -3625,11 +3637,7 @@ n8mFEtUKobsK
|
|
3625
3637
|
debug = debug.nne
|
3626
3638
|
debug.nne && (stderr.puts "#{__method__} starting")
|
3627
3639
|
debug && (stderr.puts "args=#{args.inspect}")
|
3628
|
-
|
3629
|
-
debug && (stderr.puts "args=#{args.inspect}")
|
3630
|
-
debug && (stderr.puts "will return #{is_string_repetition}")
|
3631
|
-
debug && (stderr.puts "#{__method__} returning")
|
3632
|
-
matches = operand_1.to_s.scan operand_2
|
3640
|
+
matches = (operand_1.scan operand_2) rescue []
|
3633
3641
|
amout_of_matches = matches.size
|
3634
3642
|
min_repetitions = min_repetitions.nne 0
|
3635
3643
|
is_string_repetition = (
|
@@ -3645,7 +3653,95 @@ n8mFEtUKobsK
|
|
3645
3653
|
end
|
3646
3654
|
|
3647
3655
|
|
3648
|
-
#
|
3656
|
+
# operates and/or returns a structure similar to an pushdown automaton.
|
3657
|
+
# @param [Array] +args+, an +Array+ whose elements are expected to be:
|
3658
|
+
# +pd+:: [Array] an +Array+ whose elements are :
|
3659
|
+
# +pd.operand+:: [Array] current state
|
3660
|
+
# +pd.stack+:: [Array] state stack
|
3661
|
+
# +operation_plan+:: [Array, Object] +false+ object is interpreted as no operation (only creates a pd). Otherwise, it is an +Array+ whose elements are :
|
3662
|
+
# reserved_token, reservation_type, token = operation_plan.to_a
|
3663
|
+
# +operation_plan.reserved_token+:: [Object] operates stack if +true+, otherwise, operate +state+
|
3664
|
+
# +operation_plan.reservation_type+:: [Object] pushes stack if +true+ into state, otherwise, pops.
|
3665
|
+
# +operation_plan.token+:: [Object] state operand (element that will be pushed into the current state, when operating +state+)
|
3666
|
+
# +operation_plan.bulk+:: [Object] if calling the object +nne+ method returns a +true+ value, will operate as +operation_plan.token+ is a container of tokens instead. If the object is an +Array+, it will prepend the first element and append to +pd.operand+ after the bulk insertion is done.
|
3667
|
+
# +debug+:: [Object] +debug.nne+ will be used to determine whether to output or not debug information.
|
3668
|
+
# +pd+:: [Array]
|
3669
|
+
# @return [Array] returns the operated (or a new, when no operation) +pd+
|
3670
|
+
def pushdown_operate args=[]
|
3671
|
+
stderr = @memory[:stderr]
|
3672
|
+
pd,
|
3673
|
+
operation_plan,
|
3674
|
+
debug,
|
3675
|
+
reserved = args
|
3676
|
+
|
3677
|
+
pd = pd.nne []
|
3678
|
+
array_operand,
|
3679
|
+
array_operands_stack,
|
3680
|
+
reserved = pd
|
3681
|
+
|
3682
|
+
operation_plan = operation_plan.nne
|
3683
|
+
|
3684
|
+
debug = debug.nne
|
3685
|
+
debug.nne && (stderr.puts "{#{__method__} starting")
|
3686
|
+
debug && (stderr.puts "args=#{args.inspect}")
|
3687
|
+
debug && (stderr.puts "operation_plan=#{operation_plan.inspect}")
|
3688
|
+
|
3689
|
+
array_operands_stack = array_operands_stack.nne []
|
3690
|
+
array_operand = array_operand.nne []
|
3691
|
+
|
3692
|
+
reserved_token,
|
3693
|
+
reservation_type,
|
3694
|
+
token,
|
3695
|
+
reserved_token_symbol,
|
3696
|
+
bulk = operation_plan.to_a
|
3697
|
+
bulk = bulk.nne
|
3698
|
+
debug && (stderr.puts "reserved_token=#{reserved_token.inspect}")
|
3699
|
+
debug && (stderr.puts "reservation_type=#{reservation_type.inspect}")
|
3700
|
+
debug && (stderr.puts "token=#{token.inspect}")
|
3701
|
+
debug && (stderr.puts "bulk=#{bulk.inspect}")
|
3702
|
+
operation_plan && reserved_token && (
|
3703
|
+
reservation_type && (
|
3704
|
+
debug && (stderr.puts "case is_up_token: #{token.inspect}")
|
3705
|
+
array_operands_stack.push array_operand
|
3706
|
+
array_operand = Array.new
|
3707
|
+
true
|
3708
|
+
) || (
|
3709
|
+
debug && (stderr.puts "case is_down_token: #{token.inspect}")
|
3710
|
+
# this approach:
|
3711
|
+
# array_operand = array_operands_stack.pop.push array_operand
|
3712
|
+
# won't accept pops when the stack is empty.
|
3713
|
+
# this approach:
|
3714
|
+
# array_operand = array_operands_stack.pop.to_a.push array_operand
|
3715
|
+
# will work as a "push" was added to the beginning
|
3716
|
+
# another approach (not coded here) would be stop accept
|
3717
|
+
# pushes to *array_operand* (at least when a new
|
3718
|
+
# stack push/token up is done). To keep simplicity,
|
3719
|
+
# the reset approach is done (past is forgotten),
|
3720
|
+
# but the other options are left for the case of a
|
3721
|
+
# future option implementation
|
3722
|
+
array_operand = (array_operands_stack.pop.push array_operand) rescue []
|
3723
|
+
true
|
3724
|
+
)
|
3725
|
+
) || operation_plan && (
|
3726
|
+
debug && (stderr.puts "case is_no_token: #{token.inspect}")
|
3727
|
+
|
3728
|
+
bulk_token_duck_type_method = :map
|
3729
|
+
bulk_token_push = bulk && token.respond_to?(bulk_token_duck_type_method)
|
3730
|
+
debug && (stderr.puts "[bulk, bulk_token_duck_type_method, bulk_token_push]=#{[bulk, bulk_token_duck_type_method, bulk_token_push].inspect}")
|
3731
|
+
bulk_token_push.negate_me && (array_operand.push token)
|
3732
|
+
prepend, append, reserved = bulk.to_a
|
3733
|
+
bulk_token_push && (token = [prepend, token, append].flatten(1))
|
3734
|
+
bulk_token_push && (token.map &array_operand.method(:push))
|
3735
|
+
true
|
3736
|
+
)
|
3737
|
+
pd = [array_operand, array_operands_stack]
|
3738
|
+
debug && (stderr.puts "will return #{pd.inspect}")
|
3739
|
+
debug && (stderr.puts "#{__method__} returning}")
|
3740
|
+
pd
|
3741
|
+
end
|
3742
|
+
|
3743
|
+
|
3744
|
+
# will take a flatten array and makes it deeper, starting a new array
|
3649
3745
|
# everytime it finds the string +"["+. +"]"+ stops the array (and
|
3650
3746
|
# return to the upper one). To reserve the possibility of
|
3651
3747
|
# representing "[" or "]", everytime a string contains only those
|
@@ -3656,19 +3752,58 @@ n8mFEtUKobsK
|
|
3656
3752
|
# behaviour (it will either a - transverse the sub-arrays
|
3657
3753
|
# or b - don't transverse it, leaving it untouched. while
|
3658
3754
|
# the a is the planned effect, initially only a may will
|
3659
|
-
# be implemented)
|
3660
|
-
#
|
3755
|
+
# be implemented) (currently this behaviour is easily configurable
|
3756
|
+
# by the value +deep+, hardcoded in the function. soon, new
|
3757
|
+
# functions will come to clarify and specify the proper behaviours)
|
3758
|
+
# @param [Array] +args+, an +Array+ whose elements are expected to be:
|
3759
|
+
# +flatten_array+:: [Array] the array to be operated.
|
3760
|
+
# +debug+:: [Object] if evals to false (or empty string), won't print debug information
|
3761
|
+
# +shallow+:: [Object] if evals to false (or empty string), will traverse recursively +flatten_array+ and apply the rules, in the case it is not flatten.
|
3762
|
+
# +reserved_tokens+:: [Array of Arrays]
|
3763
|
+
# +inverse+:: [Object] if calling the object +nne+ method returns a +false+ value, will operate this function inversely: will take a unflatten array and flatten it, applying the inverse escaping rules (note that any object responding to +:map+ will be considered an array in +flatten_array+).
|
3764
|
+
# +debug_pushdown+:: [Object] if evals to false (or empty string), won't print debug information about the call #pushdown_operated
|
3765
|
+
# +inversion_envelope+:: [Array, nil], if +nil+, the first colum of +reserved_tokens+ will be used. if an +Array+ whose elements are expected to be:
|
3766
|
+
# +inversion_envelope.prepend+:: [Object] when an inversion occurrs, this element will be prepended when a new object responding to +:map+, like +Array+ is found.
|
3767
|
+
# +inversion_envelope.append+:: [Object] when an inversion occurrs, this element will be prepended when a new object responding to +:map+, like +Array+ is found.
|
3661
3768
|
# @return [Array] returns the modified, deep, #Array
|
3662
|
-
def
|
3663
|
-
|
3664
|
-
|
3665
|
-
|
3769
|
+
def array_unflatten_base args=[]
|
3770
|
+
stderr = @memory[:stderr]
|
3771
|
+
flatten_array,
|
3772
|
+
shallow,
|
3773
|
+
debug,
|
3774
|
+
reserved_tokens,
|
3775
|
+
inverse,
|
3776
|
+
debug_pushdown,
|
3777
|
+
inversion_envelope,
|
3778
|
+
reserved = args
|
3779
|
+
reserved_tokens = reserved_tokens.nne [
|
3780
|
+
[ "[", :up],
|
3781
|
+
[ "]", :up.negate_me],
|
3666
3782
|
]
|
3667
|
-
|
3668
|
-
|
3669
|
-
|
3670
|
-
|
3671
|
-
|
3783
|
+
inversion_envelope = inversion_envelope.nne(
|
3784
|
+
reserved_tokens.transpose.first
|
3785
|
+
)
|
3786
|
+
inverse = inverse.nne
|
3787
|
+
shallow = shallow.nne
|
3788
|
+
debug_pushdown = debug_pushdown.nne
|
3789
|
+
debug = debug.nne
|
3790
|
+
debug.nne && (stderr.puts "{#{__method__} starting")
|
3791
|
+
debug && (stderr.puts "args=#{args.inspect}")
|
3792
|
+
pd = pushdown_operate
|
3793
|
+
flatten_array.each_with_index {|e, index|
|
3794
|
+
debug && (stderr.puts "-------------------")
|
3795
|
+
debug && (stderr.puts "[e, index]=#{[e, index].inspect}")
|
3796
|
+
shallow.negate_me && (
|
3797
|
+
debug && (stderr.puts "e.hash=#{e.hash}")
|
3798
|
+
args_recursion = args.clone
|
3799
|
+
args_recursion[0] = e
|
3800
|
+
e = (send __method__, args_recursion) rescue ( debug && (stderr.puts "#{__method__} finished with exception }" ) ; e)
|
3801
|
+
debug && (stderr.puts "e.hash=#{e.hash}")
|
3802
|
+
)
|
3803
|
+
operations = reserved_tokens.map { |reserved_token|
|
3804
|
+
debug && (stderr.puts "reserved_token=#{reserved_token.inspect}")
|
3805
|
+
debug && (stderr.puts "array_operands_stack=#{pd[1].inspect}")
|
3806
|
+
debug && (stderr.puts "array_operand=#{pd.first.inspect}")
|
3672
3807
|
rtoken, is_up_token = reserved_token
|
3673
3808
|
|
3674
3809
|
repetition_test = string_repetition [e, rtoken, 1]
|
@@ -3676,13 +3811,15 @@ n8mFEtUKobsK
|
|
3676
3811
|
# case A: e is exactly the reserved token.
|
3677
3812
|
# start or finish an array
|
3678
3813
|
# note: if rtoken is false, it will succeed this
|
3679
|
-
# test.
|
3814
|
+
# test.
|
3680
3815
|
(repetition_test == rtoken) && (
|
3816
|
+
inverse && (e = (e.sub! "", rtoken) rescue e)
|
3681
3817
|
is_up_token && (
|
3682
|
-
|
3683
|
-
|
3818
|
+
debug && (stderr.puts "case is_up_token")
|
3819
|
+
[:reserved_token.negate_me(inverse), :up, e, rtoken, false ]
|
3684
3820
|
) || (
|
3685
|
-
|
3821
|
+
debug && (stderr.puts "case is_down_token")
|
3822
|
+
[:reserved_token.negate_me(inverse), :up.negate_me, e, rtoken, false ]
|
3686
3823
|
)
|
3687
3824
|
)
|
3688
3825
|
) || (
|
@@ -3690,34 +3827,70 @@ n8mFEtUKobsK
|
|
3690
3827
|
# occurrences of the reserved token. remove one.
|
3691
3828
|
# (and add it to the current array)
|
3692
3829
|
repetition_test && (
|
3693
|
-
|
3830
|
+
debug && (stderr.puts "case escape")
|
3831
|
+
# room for improvement: and if array had sub! ?
|
3832
|
+
!inverse && (escaped_e = (e.sub! rtoken, "") rescue e)
|
3833
|
+
[:reserved_token.negate_me, nil, escaped_e, rtoken, false ]
|
3694
3834
|
)
|
3695
3835
|
) || (
|
3696
3836
|
# case C: no repetition. (just add e to
|
3697
3837
|
# the current array.)
|
3698
|
-
|
3838
|
+
debug && (stderr.puts "case just add")
|
3839
|
+
[:reserved_token.negate_me, nil, e, rtoken, inverse && inversion_envelope ]
|
3699
3840
|
)
|
3700
3841
|
}
|
3842
|
+
# now operations has |reserved_tokens| operations.
|
3843
|
+
# but only one will be applied: either the first
|
3844
|
+
# one which is a reserved token (:first), or the
|
3845
|
+
# last operation, in case of no reserved tokens.
|
3846
|
+
operation = operations.lazy.find(&:first) || (
|
3847
|
+
operations[-1].to_a
|
3848
|
+
)
|
3849
|
+
reserved_token, reservation_type, token = operation
|
3850
|
+
pd = pushdown_operate [pd, operation, debug_pushdown]
|
3701
3851
|
}
|
3702
|
-
|
3852
|
+
debug && (stderr.puts "will return #{pd.first}")
|
3853
|
+
debug && (stderr.puts "#{__method__} returning}")
|
3854
|
+
pd.first
|
3703
3855
|
end
|
3704
3856
|
|
3705
|
-
# test for #string_repetition
|
3706
|
-
def test__array_unflatten_base_shallow args=[]
|
3707
|
-
test_cases ||= [
|
3708
|
-
# [ :id, :expectation, :actual_params ],
|
3709
|
-
# array_unflatten_base_shallow
|
3710
|
-
[ "any test", [ :a, [ :b ], :c], [
|
3711
|
-
:array_unflatten_base_shallow, [
|
3712
|
-
:a, "[", :b, "]", :c
|
3713
|
-
]
|
3714
|
-
],
|
3715
|
-
],
|
3716
3857
|
|
3858
|
+
# takes a flatten array and makes it deeper, starting a new array
|
3859
|
+
# everytime it finds the string +"["+. +"]"+ stops the array (and
|
3860
|
+
# return to the upper one). To reserve the possibility of
|
3861
|
+
# representing "[" or "]", everytime a string contains only those
|
3862
|
+
# chars, repeteaded any number of times, starting from 2, one of
|
3863
|
+
# them will be removed. So +"[["+ will be left as +"["+ and
|
3864
|
+
# +"]]]"+ will be left as +"]]"+.
|
3865
|
+
# if the provided array is not flatten, it won't be transversed.
|
3866
|
+
# @param [Array] +args+, the array to be operadated
|
3867
|
+
# @return [Array] returns the modified, deep, #Array
|
3868
|
+
def array_unflatten_base_shallow args=[]
|
3869
|
+
stderr = @memory[:stderr]
|
3870
|
+
deep = false
|
3871
|
+
reserved_tokens = [
|
3872
|
+
[ "[", :up],
|
3873
|
+
[ "]", :up.negate_me],
|
3717
3874
|
]
|
3718
|
-
|
3875
|
+
# debug = 1
|
3876
|
+
debug = debug.nne
|
3877
|
+
debug.nne && (stderr.puts "#{__method__} starting")
|
3878
|
+
debug && (stderr.puts "args=#{args.inspect}")
|
3879
|
+
|
3880
|
+
rv = array_unflatten_base [
|
3881
|
+
args,
|
3882
|
+
deep.negate_me,
|
3883
|
+
debug,
|
3884
|
+
reserved_tokens,
|
3885
|
+
]
|
3886
|
+
|
3887
|
+
debug && (stderr.puts "will return #{rv}")
|
3888
|
+
debug && (stderr.puts "#{__method__} returning")
|
3889
|
+
rv
|
3719
3890
|
end
|
3720
3891
|
|
3892
|
+
|
3893
|
+
# generic function for test__ functions
|
3721
3894
|
def test__tester args=[]
|
3722
3895
|
expectation = {}
|
3723
3896
|
actual = {}
|
@@ -3737,6 +3910,215 @@ n8mFEtUKobsK
|
|
3737
3910
|
end
|
3738
3911
|
|
3739
3912
|
|
3913
|
+
# test for #array_unflatten_base_shallow
|
3914
|
+
def test__array_unflatten_base_shallow args=[]
|
3915
|
+
test_cases ||= [
|
3916
|
+
# [ :id, :expectation, :actual_params ],
|
3917
|
+
[
|
3918
|
+
"base_case", [ :a, [ :b ], :c], [
|
3919
|
+
:array_unflatten_base_shallow, [
|
3920
|
+
:a, "[", :b, "]", :c
|
3921
|
+
]
|
3922
|
+
],
|
3923
|
+
],
|
3924
|
+
|
3925
|
+
[
|
3926
|
+
"base_escape_case", [ :a, "[", :b, "]", :c], [
|
3927
|
+
:array_unflatten_base_shallow, [
|
3928
|
+
:a, "[[", :b, "]]", :c
|
3929
|
+
]
|
3930
|
+
],
|
3931
|
+
],
|
3932
|
+
|
3933
|
+
[
|
3934
|
+
"base_open_right_case", [ :c], [
|
3935
|
+
:array_unflatten_base_shallow, [
|
3936
|
+
:a, :b, "[", :c
|
3937
|
+
]
|
3938
|
+
],
|
3939
|
+
],
|
3940
|
+
|
3941
|
+
[
|
3942
|
+
"base_open_left_case", [ :b, :c], [
|
3943
|
+
:array_unflatten_base_shallow, [
|
3944
|
+
:a, "]", :b, :c
|
3945
|
+
]
|
3946
|
+
],
|
3947
|
+
],
|
3948
|
+
|
3949
|
+
[
|
3950
|
+
"base_case_double", [ :a, [ [ :b ] ], :c], [
|
3951
|
+
:array_unflatten_base_shallow, [
|
3952
|
+
:a, "[", "[", :b, "]", "]", :c
|
3953
|
+
]
|
3954
|
+
],
|
3955
|
+
],
|
3956
|
+
|
3957
|
+
[
|
3958
|
+
"base_case_inverted", [ :c], [
|
3959
|
+
:array_unflatten_base_shallow, [
|
3960
|
+
:a, "]", :b, "[", :c
|
3961
|
+
]
|
3962
|
+
],
|
3963
|
+
],
|
3964
|
+
|
3965
|
+
|
3966
|
+
[
|
3967
|
+
"base_nested_case", [ :a, [ [ :b ] ], :c], [
|
3968
|
+
:array_unflatten_base_shallow, [
|
3969
|
+
:a, "[", [ :b ], "]", :c
|
3970
|
+
]
|
3971
|
+
],
|
3972
|
+
],
|
3973
|
+
|
3974
|
+
|
3975
|
+
[
|
3976
|
+
"base_mixed_nested_case", [ :a, [ [ "[", :b, "]", ] ], :c], [
|
3977
|
+
:array_unflatten_base_shallow, [
|
3978
|
+
:a, "[", [ "[", :b, "]", ], "]", :c
|
3979
|
+
]
|
3980
|
+
],
|
3981
|
+
],
|
3982
|
+
|
3983
|
+
|
3984
|
+
]
|
3985
|
+
test__tester test_cases
|
3986
|
+
end
|
3987
|
+
|
3988
|
+
|
3989
|
+
# test for #array_unflatten_base
|
3990
|
+
def test__array_unflatten_base args=[]
|
3991
|
+
test_cases ||= [
|
3992
|
+
# [ :id, :expectation, :actual_params ],
|
3993
|
+
[
|
3994
|
+
"base_case", [ :a, [ :b ], :c], [
|
3995
|
+
:array_unflatten_base, [
|
3996
|
+
[:a, "[", :b, "]", :c],
|
3997
|
+
:shallow,
|
3998
|
+
:debug.negate_me,
|
3999
|
+
:reserved_tokens.to_nil,
|
4000
|
+
:inverse.negate_me,
|
4001
|
+
]
|
4002
|
+
],
|
4003
|
+
],
|
4004
|
+
|
4005
|
+
[
|
4006
|
+
"base_escape_case", [ :a, "[", :b, "]", :c], [
|
4007
|
+
:array_unflatten_base, [
|
4008
|
+
[:a, "[[", :b, "]]", :c],
|
4009
|
+
:shallow,
|
4010
|
+
:debug.negate_me,
|
4011
|
+
:reserved_tokens.to_nil,
|
4012
|
+
:inverse.negate_me,
|
4013
|
+
]
|
4014
|
+
],
|
4015
|
+
],
|
4016
|
+
|
4017
|
+
[
|
4018
|
+
"base_open_right_case", [ :c], [
|
4019
|
+
:array_unflatten_base, [
|
4020
|
+
[:a, :b, "[", :c],
|
4021
|
+
:shallow,
|
4022
|
+
:debug.negate_me,
|
4023
|
+
:reserved_tokens.to_nil,
|
4024
|
+
:inverse.negate_me,
|
4025
|
+
]
|
4026
|
+
],
|
4027
|
+
],
|
4028
|
+
|
4029
|
+
[
|
4030
|
+
"base_open_left_case", [ :b, :c], [
|
4031
|
+
:array_unflatten_base, [
|
4032
|
+
[:a, "]", :b, :c],
|
4033
|
+
:shallow,
|
4034
|
+
:debug.negate_me,
|
4035
|
+
:reserved_tokens.to_nil,
|
4036
|
+
:inverse.negate_me,
|
4037
|
+
]
|
4038
|
+
],
|
4039
|
+
],
|
4040
|
+
|
4041
|
+
[
|
4042
|
+
"base_case_double", [ :a, [ [ :b ] ], :c], [
|
4043
|
+
:array_unflatten_base, [
|
4044
|
+
[:a, "[", "[", :b, "]", "]", :c],
|
4045
|
+
:shallow,
|
4046
|
+
:debug.negate_me,
|
4047
|
+
:reserved_tokens.to_nil,
|
4048
|
+
:inverse.negate_me,
|
4049
|
+
]
|
4050
|
+
],
|
4051
|
+
],
|
4052
|
+
|
4053
|
+
[
|
4054
|
+
"base_case_inverted", [ :c], [
|
4055
|
+
:array_unflatten_base, [
|
4056
|
+
[:a, "]", :b, "[", :c],
|
4057
|
+
:shallow,
|
4058
|
+
:debug.negate_me,
|
4059
|
+
:reserved_tokens.to_nil,
|
4060
|
+
:inverse.negate_me,
|
4061
|
+
]
|
4062
|
+
],
|
4063
|
+
],
|
4064
|
+
|
4065
|
+
|
4066
|
+
[
|
4067
|
+
"base_nested_case", [ :a, [ [ :b ] ], :c], [
|
4068
|
+
:array_unflatten_base, [
|
4069
|
+
[:a, "[", [ :b ], "]", :c],
|
4070
|
+
:shallow,
|
4071
|
+
:debug.negate_me,
|
4072
|
+
:reserved_tokens.to_nil,
|
4073
|
+
:inverse.negate_me,
|
4074
|
+
]
|
4075
|
+
],
|
4076
|
+
],
|
4077
|
+
|
4078
|
+
|
4079
|
+
[
|
4080
|
+
"base_mixed_nested_case_deep", [ :a, [ [ [ :b, ] ] ], :c], [
|
4081
|
+
:array_unflatten_base, [
|
4082
|
+
[:a, "[", [ "[", :b, "]", ], "]", :c],
|
4083
|
+
:shallow.negate_me,
|
4084
|
+
:debug.negate_me,
|
4085
|
+
:reserved_tokens.to_nil,
|
4086
|
+
:inverse.negate_me,
|
4087
|
+
]
|
4088
|
+
],
|
4089
|
+
],
|
4090
|
+
|
4091
|
+
|
4092
|
+
[
|
4093
|
+
"base_mixed_nested_case_shallow", [ :a, [ [ "[", :b, "]", ] ], :c], [
|
4094
|
+
:array_unflatten_base, [
|
4095
|
+
[ :a, "[", [ "[", :b, "]", ], "]", :c ],
|
4096
|
+
:shallow,
|
4097
|
+
:debug.negate_me,
|
4098
|
+
:reserved_tokens.to_nil,
|
4099
|
+
:inverse.negate_me,
|
4100
|
+
]
|
4101
|
+
],
|
4102
|
+
],
|
4103
|
+
|
4104
|
+
[
|
4105
|
+
"base_case_inverse", [ :a, "[", :b, "]", :c], [
|
4106
|
+
:array_unflatten_base, [
|
4107
|
+
[:a, [ :b, ], :c],
|
4108
|
+
:shallow.negate_me,
|
4109
|
+
:debug.negate_me,
|
4110
|
+
:reserved_tokens.to_nil,
|
4111
|
+
:inverse,
|
4112
|
+
]
|
4113
|
+
],
|
4114
|
+
],
|
4115
|
+
|
4116
|
+
|
4117
|
+
]
|
4118
|
+
test__tester test_cases
|
4119
|
+
end
|
4120
|
+
|
4121
|
+
|
3740
4122
|
# test for #string_repetition
|
3741
4123
|
def test__string_repetition args=[]
|
3742
4124
|
expectation = {}
|
@@ -3745,84 +4127,140 @@ n8mFEtUKobsK
|
|
3745
4127
|
operand_1 = "XXX"
|
3746
4128
|
operand_2 = "X"
|
3747
4129
|
# expectation and actual inverted.
|
3748
|
-
|
3749
|
-
|
4130
|
+
actual[test_case] = string_repetition [operand_1, operand_2]
|
4131
|
+
expectation[test_case] = operand_1
|
3750
4132
|
|
3751
4133
|
test_case = 2
|
3752
4134
|
operand_1 = "X"
|
3753
4135
|
operand_2 = "X"
|
3754
|
-
|
3755
|
-
|
4136
|
+
actual[test_case] = string_repetition [operand_1, operand_2]
|
4137
|
+
expectation[test_case] = operand_1
|
3756
4138
|
|
3757
4139
|
test_case = 3
|
3758
4140
|
operand_1 = "XyXy"
|
3759
4141
|
operand_2 = "XyXy"
|
3760
|
-
|
3761
|
-
|
4142
|
+
actual[test_case] = string_repetition [operand_1, operand_2]
|
4143
|
+
expectation[test_case] = operand_1
|
3762
4144
|
|
3763
4145
|
test_case = 4
|
3764
4146
|
operand_1 = "XyXy"
|
3765
4147
|
operand_2 = "XXyy"
|
3766
|
-
|
3767
|
-
|
4148
|
+
actual[test_case] = string_repetition [operand_1, operand_2]
|
4149
|
+
expectation[test_case] = false
|
3768
4150
|
|
3769
4151
|
test_case = 6
|
3770
4152
|
operand_1 = ""
|
3771
4153
|
operand_2 = ""
|
3772
|
-
|
3773
|
-
|
4154
|
+
actual[test_case] = string_repetition [operand_1, operand_2, 0]
|
4155
|
+
expectation[test_case] = operand_1
|
3774
4156
|
|
3775
4157
|
test_case = 7
|
3776
4158
|
operand_1 = ""
|
3777
4159
|
operand_2 = ""
|
3778
|
-
|
3779
|
-
|
4160
|
+
actual[test_case] = string_repetition [operand_1, operand_2, 1]
|
4161
|
+
expectation[test_case] = operand_1
|
3780
4162
|
|
3781
4163
|
test_case = 7
|
3782
4164
|
operand_1 = ""
|
3783
4165
|
operand_2 = "X"
|
3784
|
-
|
4166
|
+
actual[test_case] = string_repetition [operand_1, operand_2, 0]
|
3785
4167
|
# "X"*0 = ""
|
3786
|
-
|
4168
|
+
expectation[test_case] = operand_1
|
3787
4169
|
|
3788
4170
|
test_case = 8
|
3789
4171
|
operand_1 = ""
|
3790
4172
|
operand_2 = "X"
|
3791
|
-
|
4173
|
+
actual[test_case] = string_repetition [operand_1, operand_2, 1]
|
3792
4174
|
# "X"*0 = "", but minimum is set to 1
|
3793
|
-
|
4175
|
+
expectation[test_case] = false
|
3794
4176
|
|
3795
4177
|
test_case = 9
|
3796
4178
|
operand_1 = "XyXy"
|
3797
4179
|
operand_2 = "Xy"
|
3798
|
-
|
3799
|
-
|
4180
|
+
actual[test_case] = string_repetition [operand_1, operand_2]
|
4181
|
+
expectation[test_case] = operand_1
|
3800
4182
|
|
3801
4183
|
test_case = 10
|
3802
4184
|
operand_1 = "XyXy"
|
3803
4185
|
operand_2 = ""
|
3804
|
-
|
4186
|
+
actual[test_case] = string_repetition [operand_1, operand_2]
|
3805
4187
|
# clearly "" appears in "XyXy" infinity times, but "XyXy" is no
|
3806
4188
|
# repetition of ""
|
3807
|
-
|
4189
|
+
expectation[test_case] = false
|
3808
4190
|
|
3809
4191
|
test_case = 11
|
3810
4192
|
operand_1 = "XyXy"
|
3811
4193
|
operand_2 = "Xy"
|
3812
|
-
|
3813
|
-
|
4194
|
+
actual[test_case] = string_repetition [operand_1, operand_2]
|
4195
|
+
expectation[test_case] = operand_1
|
3814
4196
|
|
3815
4197
|
test_case = 12
|
3816
4198
|
operand_1 = "X"
|
3817
4199
|
operand_2 = "XXX"
|
3818
|
-
|
3819
|
-
|
4200
|
+
actual[test_case] = string_repetition [operand_1, operand_2]
|
4201
|
+
expectation[test_case] = false
|
4202
|
+
|
4203
|
+
test_case = 13
|
4204
|
+
operand_1 = [:b]
|
4205
|
+
operand_2 = "]"
|
4206
|
+
actual[test_case] = string_repetition [operand_1, operand_2]
|
4207
|
+
expectation[test_case] = false
|
4208
|
+
|
4209
|
+
test_case = 14
|
4210
|
+
operand_1 = "[:b]"
|
4211
|
+
operand_2 = "]"
|
4212
|
+
actual[test_case] = string_repetition [operand_1, operand_2]
|
4213
|
+
expectation[test_case] = false
|
3820
4214
|
|
3821
4215
|
judgement = actual.keys.map {|test_case|
|
3822
4216
|
[expectation[test_case], actual[test_case] , test_case]
|
3823
4217
|
}.map(&method("expect_equal")).all?
|
3824
4218
|
end
|
3825
4219
|
|
4220
|
+
# test #rest_request
|
4221
|
+
# for now, the parameters must still be hardcoded.
|
4222
|
+
def test__rest_request__with_ayt args=ARGV
|
4223
|
+
require 'json'
|
4224
|
+
stderr = @memory[:stderr]
|
4225
|
+
|
4226
|
+
url = "https://owl.loftweb.nl:55031/4/3-roOomydev"
|
4227
|
+
json =<<-ENDHEREDOC
|
4228
|
+
{
|
4229
|
+
"operation" : "AYT",
|
4230
|
+
"version" : {
|
4231
|
+
"client" : "X",
|
4232
|
+
"protocol" : {
|
4233
|
+
"domain_model" : "4",
|
4234
|
+
"API" : "3"
|
4235
|
+
}
|
4236
|
+
}
|
4237
|
+
}
|
4238
|
+
ENDHEREDOC
|
4239
|
+
payload = "#{json}"
|
4240
|
+
|
4241
|
+
auth_user = "web"
|
4242
|
+
password = "vadim"
|
4243
|
+
method = :post
|
4244
|
+
method = :get
|
4245
|
+
timeout = 600
|
4246
|
+
verify_ssl = true
|
4247
|
+
payload = "#{json}"
|
4248
|
+
headers = ""
|
4249
|
+
request_execution = send :rest_response__request_base, [
|
4250
|
+
url,
|
4251
|
+
payload,
|
4252
|
+
verify_ssl,
|
4253
|
+
headers,
|
4254
|
+
method,
|
4255
|
+
auth_user,
|
4256
|
+
password,
|
4257
|
+
timeout,
|
4258
|
+
]
|
4259
|
+
parsed_json = JSON.parse request_execution.first.to_s
|
4260
|
+
[parsed_json]
|
4261
|
+
end
|
4262
|
+
|
4263
|
+
|
3826
4264
|
|
3827
4265
|
|
3828
4266
|
end
|